mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-08 20:22:22 +02:00
Don't manage _sendData's memory
This commit is contained in:
parent
ec9d13700d
commit
b2704da9ef
2 changed files with 20 additions and 33 deletions
|
@ -30,30 +30,14 @@ Q_DECLARE_METATYPE(QByteArray*)
|
|||
|
||||
XMLHttpRequestClass::XMLHttpRequestClass(QScriptEngine* engine) :
|
||||
_engine(engine),
|
||||
_async(true),
|
||||
_url(),
|
||||
_method(""),
|
||||
_responseType(""),
|
||||
_request(),
|
||||
_reply(NULL),
|
||||
_sendData(NULL),
|
||||
_rawResponseData(),
|
||||
_responseData(""),
|
||||
_onTimeout(QScriptValue::NullValue),
|
||||
_onReadyStateChange(QScriptValue::NullValue),
|
||||
_readyState(XMLHttpRequestClass::UNSENT),
|
||||
_errorCode(QNetworkReply::NoError),
|
||||
_timeout(0),
|
||||
_timer(this),
|
||||
_numRedirects(0) {
|
||||
_timer(this) {
|
||||
|
||||
_request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
|
||||
_timer.setSingleShot(true);
|
||||
}
|
||||
|
||||
XMLHttpRequestClass::~XMLHttpRequestClass() {
|
||||
if (_reply) { delete _reply; }
|
||||
if (_sendData) { delete _sendData; }
|
||||
if (_reply) { _reply->deleteLater(); }
|
||||
}
|
||||
|
||||
QScriptValue XMLHttpRequestClass::constructor(QScriptContext* context, QScriptEngine* engine) {
|
||||
|
@ -169,13 +153,12 @@ void XMLHttpRequestClass::send() {
|
|||
|
||||
void XMLHttpRequestClass::send(const QScriptValue& data) {
|
||||
if (_readyState == OPENED && !_reply) {
|
||||
|
||||
if (!data.isNull()) {
|
||||
_sendData = new QBuffer(this);
|
||||
if (data.isObject()) {
|
||||
QByteArray ba = qscriptvalue_cast<QByteArray>(data);
|
||||
_sendData->setData(ba);
|
||||
_sendData = qscriptvalue_cast<QByteArray>(data);
|
||||
} else {
|
||||
_sendData->setData(data.toString().toUtf8());
|
||||
_sendData = data.toString().toUtf8();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -235,6 +218,10 @@ void XMLHttpRequestClass::requestFinished() {
|
|||
}
|
||||
}
|
||||
|
||||
disconnectFromReply(_reply);
|
||||
_reply->deleteLater();
|
||||
_reply = nullptr;
|
||||
|
||||
setReadyState(DONE);
|
||||
emit requestComplete();
|
||||
}
|
||||
|
@ -246,7 +233,7 @@ void XMLHttpRequestClass::abortRequest() {
|
|||
disconnectFromReply(_reply);
|
||||
_reply->abort();
|
||||
_reply->deleteLater();
|
||||
_reply = NULL;
|
||||
_reply = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -98,23 +98,23 @@ private:
|
|||
void disconnectFromReply(QNetworkReply* reply);
|
||||
void abortRequest();
|
||||
|
||||
QScriptEngine* _engine;
|
||||
bool _async;
|
||||
QScriptEngine* _engine { nullptr };
|
||||
bool _async { true };
|
||||
QUrl _url;
|
||||
QString _method;
|
||||
QString _responseType;
|
||||
QNetworkRequest _request;
|
||||
QNetworkReply* _reply;
|
||||
QBuffer* _sendData;
|
||||
QNetworkReply* _reply { nullptr };
|
||||
QByteArray _sendData;
|
||||
QByteArray _rawResponseData;
|
||||
QScriptValue _responseData;
|
||||
QScriptValue _onTimeout;
|
||||
QScriptValue _onReadyStateChange;
|
||||
ReadyState _readyState;
|
||||
QNetworkReply::NetworkError _errorCode;
|
||||
int _timeout;
|
||||
QScriptValue _onTimeout { QScriptValue::NullValue };
|
||||
QScriptValue _onReadyStateChange { QScriptValue::NullValue };
|
||||
ReadyState _readyState { XMLHttpRequestClass::UNSENT };
|
||||
QNetworkReply::NetworkError _errorCode { QNetworkReply::NoError };
|
||||
int _timeout { 0 };
|
||||
QTimer _timer;
|
||||
int _numRedirects;
|
||||
int _numRedirects { 0 };
|
||||
|
||||
private slots:
|
||||
void requestFinished();
|
||||
|
|
Loading…
Reference in a new issue