Fix potential crash in the reply proxy.

The cause is not clear, either the object ownership issue (circular
reference) or some race condition (or worse, both combination).
In all cases, using QPointer avoids dereferencing a null object.

http://code.google.com/p/phantomjs/issues/detail?id=158
1.3
Ariya Hidayat 2011-09-14 22:47:26 -07:00
parent 7a9b6b4fec
commit 37404ba179
2 changed files with 9 additions and 5 deletions

View File

@ -57,7 +57,8 @@ NetworkReplyProxy::NetworkReplyProxy(QObject* parent, QNetworkReply* reply)
NetworkReplyProxy::~NetworkReplyProxy()
{
delete m_reply;
if (m_reply)
delete m_reply;
}
QString NetworkReplyProxy::body()
@ -66,13 +67,15 @@ QString NetworkReplyProxy::body()
}
void NetworkReplyProxy::abort()
{
m_reply->abort();
{
if (m_reply)
m_reply->abort();
}
void NetworkReplyProxy::close()
{
m_reply->close();
if (m_reply)
m_reply->close();
}
bool NetworkReplyProxy::isSequential() const

View File

@ -31,6 +31,7 @@
#define NETWORKREPLYPROXY_H
#include <QNetworkReply>
#include <QPointer>
class NetworkReplyProxy : public QNetworkReply {
Q_OBJECT
@ -60,7 +61,7 @@ public Q_SLOTS:
void readInternal();
private:
QNetworkReply* m_reply;
QPointer<QNetworkReply> m_reply;
QByteArray m_data;
QByteArray m_buffer;
};