History

Don't manage _sendData's memory

Clement committed 7 years ago

Commit b2704da1 parent ec9d1372 files · +20 −33Browse files

Showing the changes to libraries/script-engine/src/XMLHttpRequestClass.cpp (1 of 2 files). Show all

Unified · Split

libraries/script-engine/src/XMLHttpRequestClass.cpp+10−23
@@ -30,30 +30,14 @@ Q_DECLARE_METATYPE(QByteArray*) · 29 unmodified lines
30 30
31XMLHttpRequestClass::XMLHttpRequestClass(QScriptEngine* engine) :31XMLHttpRequestClass::XMLHttpRequestClass(QScriptEngine* engine) :
32 _engine(engine),32 _engine(engine),
33 _async(true),33 _timer(this) {
34 _url(),
35 _method(""),
36 _responseType(""),
37 _request(),
38 _reply(NULL),
39 _sendData(NULL),
40 _rawResponseData(),
41 _responseData(""),
42 _onTimeout(QScriptValue::NullValue),
43 _onReadyStateChange(QScriptValue::NullValue),
44 _readyState(XMLHttpRequestClass::UNSENT),
45 _errorCode(QNetworkReply::NoError),
46 _timeout(0),
47 _timer(this),
48 _numRedirects(0) {
49 34
50 _request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);35 _request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
51 _timer.setSingleShot(true);36 _timer.setSingleShot(true);
52}37}
53 38
54XMLHttpRequestClass::~XMLHttpRequestClass() {39XMLHttpRequestClass::~XMLHttpRequestClass() {
55 if (_reply) { delete _reply; }40 if (_reply) { _reply->deleteLater(); }
56 if (_sendData) { delete _sendData; }
57}41}
58 42
59QScriptValue XMLHttpRequestClass::constructor(QScriptContext* context, QScriptEngine* engine) {43QScriptValue XMLHttpRequestClass::constructor(QScriptContext* context, QScriptEngine* engine) {
@@ -169,13 +153,12 @@ void XMLHttpRequestClass::send() { · 109 unmodified lines
169 153
170void XMLHttpRequestClass::send(const QScriptValue& data) {154void XMLHttpRequestClass::send(const QScriptValue& data) {
171 if (_readyState == OPENED && !_reply) {155 if (_readyState == OPENED && !_reply) {
156
172 if (!data.isNull()) {157 if (!data.isNull()) {
173 _sendData = new QBuffer(this);
174 if (data.isObject()) {158 if (data.isObject()) {
175 QByteArray ba = qscriptvalue_cast<QByteArray>(data);159 _sendData = qscriptvalue_cast<QByteArray>(data);
176 _sendData->setData(ba);
177 } else {160 } else {
178 _sendData->setData(data.toString().toUtf8());161 _sendData = data.toString().toUtf8();
179 }162 }
180 }163 }
181 164
@@ -235,6 +218,10 @@ void XMLHttpRequestClass::requestFinished() { · 53 unmodified lines
235 }218 }
236 }219 }
237 220
221 disconnectFromReply(_reply);
222 _reply->deleteLater();
223 _reply = nullptr;
224
238 setReadyState(DONE);225 setReadyState(DONE);
239 emit requestComplete();226 emit requestComplete();
240}227}
@@ -246,7 +233,7 @@ void XMLHttpRequestClass::abortRequest() { · 5 unmodified lines
246 disconnectFromReply(_reply);233 disconnectFromReply(_reply);
247 _reply->abort();234 _reply->abort();
248 _reply->deleteLater();235 _reply->deleteLater();
249 _reply = NULL;236 _reply = nullptr;
250 }237 }
251}238}
252 239