summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
Diffstat (limited to 'src/network')
-rw-r--r--src/network/access/qftp.cpp12
-rw-r--r--src/network/access/qhttp.cpp1
-rw-r--r--src/network/access/qhttp.h3
-rw-r--r--src/network/access/qhttpnetworkconnection.cpp6
-rw-r--r--src/network/access/qhttpnetworkconnection_p.h4
-rw-r--r--src/network/access/qnetworkaccesshttpbackend.cpp12
-rw-r--r--src/network/access/qnetworkaccessmanager.cpp2
-rw-r--r--src/network/access/qnetworkdiskcache.cpp42
-rw-r--r--src/network/access/qnetworkrequest.cpp3
-rw-r--r--src/network/kernel/qhostaddress.cpp5
-rw-r--r--src/network/kernel/qhostaddress.h3
-rw-r--r--src/network/kernel/qhostinfo.cpp20
-rw-r--r--src/network/kernel/qhostinfo.h3
-rw-r--r--src/network/kernel/qhostinfo_unix.cpp2
-rw-r--r--src/network/kernel/qnetworkinterface.cpp5
-rw-r--r--src/network/kernel/qnetworkinterface.h3
-rw-r--r--src/network/kernel/qnetworkinterface_win.cpp11
-rw-r--r--src/network/socket/qlocalsocket_unix.cpp2
-rw-r--r--src/network/socket/qsocks5socketengine.cpp4
-rw-r--r--src/network/socket/qtcpserver.cpp7
-rw-r--r--src/network/ssl/qsslcertificate.cpp13
-rw-r--r--src/network/ssl/qsslcertificate.h2
-rw-r--r--src/network/ssl/qsslcipher.cpp5
-rw-r--r--src/network/ssl/qsslcipher.h3
-rw-r--r--src/network/ssl/qsslerror.cpp5
-rw-r--r--src/network/ssl/qsslerror.h2
-rw-r--r--src/network/ssl/qsslkey.cpp17
-rw-r--r--src/network/ssl/qsslkey.h3
28 files changed, 109 insertions, 91 deletions
diff --git a/src/network/access/qftp.cpp b/src/network/access/qftp.cpp
index 569d2fd..c54c420 100644
--- a/src/network/access/qftp.cpp
+++ b/src/network/access/qftp.cpp
@@ -314,8 +314,10 @@ void QFtpDTP::connectToHost(const QString & host, quint16 port)
{
bytesFromSocket.clear();
- if (socket)
+ if (socket) {
delete socket;
+ socket = 0;
+ }
socket = new QTcpSocket(this);
socket->setObjectName(QLatin1String("QFtpDTP Passive state socket"));
connect(socket, SIGNAL(connected()), SLOT(socketConnected()));
@@ -1658,11 +1660,12 @@ QFtp::QFtp(QObject *parent, const char *name)
*/
int QFtp::connectToHost(const QString &host, quint16 port)
{
- d_func()->pi.transferConnectionExtended = true;
QStringList cmds;
cmds << host;
cmds << QString::number((uint)port);
- return d_func()->addCommand(new QFtpCommand(ConnectToHost, cmds));
+ int id = d_func()->addCommand(new QFtpCommand(ConnectToHost, cmds));
+ d_func()->pi.transferConnectionExtended = true;
+ return id;
}
/*!
@@ -1721,9 +1724,10 @@ int QFtp::close()
*/
int QFtp::setTransferMode(TransferMode mode)
{
+ int id = d_func()->addCommand(new QFtpCommand(SetTransferMode, QStringList()));
d_func()->pi.transferConnectionExtended = true;
d_func()->transferMode = mode;
- return d_func()->addCommand(new QFtpCommand(SetTransferMode, QStringList()));
+ return id;
}
/*!
diff --git a/src/network/access/qhttp.cpp b/src/network/access/qhttp.cpp
index 30befb3..332c67b 100644
--- a/src/network/access/qhttp.cpp
+++ b/src/network/access/qhttp.cpp
@@ -624,7 +624,6 @@ QHttpHeader::QHttpHeader(QHttpHeaderPrivate &dd, const QHttpHeader &header)
*/
QHttpHeader::~QHttpHeader()
{
- delete d_ptr;
}
/*!
diff --git a/src/network/access/qhttp.h b/src/network/access/qhttp.h
index 771176a..d575644 100644
--- a/src/network/access/qhttp.h
+++ b/src/network/access/qhttp.h
@@ -46,6 +46,7 @@
#include <QtCore/qstringlist.h>
#include <QtCore/qmap.h>
#include <QtCore/qpair.h>
+#include <QtCore/qscopedpointer.h>
QT_BEGIN_HEADER
@@ -108,7 +109,7 @@ protected:
QHttpHeader(QHttpHeaderPrivate &dd, const QString &str = QString());
QHttpHeader(QHttpHeaderPrivate &dd, const QHttpHeader &header);
- QHttpHeaderPrivate *d_ptr;
+ QScopedPointer<QHttpHeaderPrivate> d_ptr;
private:
Q_DECLARE_PRIVATE(QHttpHeader)
diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp
index ae518df..cec9c87 100644
--- a/src/network/access/qhttpnetworkconnection.cpp
+++ b/src/network/access/qhttpnetworkconnection.cpp
@@ -77,8 +77,10 @@ QHttpNetworkConnectionPrivate::QHttpNetworkConnectionPrivate(const QString &host
QHttpNetworkConnectionPrivate::~QHttpNetworkConnectionPrivate()
{
for (int i = 0; i < channelCount; ++i) {
- channels[i].socket->close();
- delete channels[i].socket;
+ if (channels[i].socket) {
+ channels[i].socket->close();
+ delete channels[i].socket;
+ }
}
}
diff --git a/src/network/access/qhttpnetworkconnection_p.h b/src/network/access/qhttpnetworkconnection_p.h
index 09bd459..0f80bd9 100644
--- a/src/network/access/qhttpnetworkconnection_p.h
+++ b/src/network/access/qhttpnetworkconnection_p.h
@@ -244,8 +244,8 @@ public:
#ifndef QT_NO_OPENSSL
bool ignoreSSLErrors;
#endif
- Channel() :state(IdleState), reply(0), written(0), bytesTotal(0), resendCurrent(false), reconnectAttempts(2),
- authMehtod(QAuthenticatorPrivate::None), proxyAuthMehtod(QAuthenticatorPrivate::None)
+ Channel() : socket(0), state(IdleState), reply(0), written(0), bytesTotal(0), resendCurrent(false),
+ reconnectAttempts(2), authMehtod(QAuthenticatorPrivate::None), proxyAuthMehtod(QAuthenticatorPrivate::None)
#ifndef QT_NO_OPENSSL
, ignoreSSLErrors(false)
#endif
diff --git a/src/network/access/qnetworkaccesshttpbackend.cpp b/src/network/access/qnetworkaccesshttpbackend.cpp
index f214699..4874d9d 100644
--- a/src/network/access/qnetworkaccesshttpbackend.cpp
+++ b/src/network/access/qnetworkaccesshttpbackend.cpp
@@ -605,6 +605,7 @@ void QNetworkAccessHttpBackend::open()
QNetworkAccessCache *cache = QNetworkAccessManagerPrivate::getCache(this);
if ((http = static_cast<QNetworkAccessHttpBackendCache *>(cache->requestEntryNow(cacheKey))) == 0) {
// no entry in cache; create an object
+ //### thiago: can we try/catch/ignore this????
http = new QNetworkAccessHttpBackendCache(url.host(), url.port(), encrypt);
#ifndef QT_NO_NETWORKPROXY
@@ -732,10 +733,15 @@ void QNetworkAccessHttpBackend::replyFinished()
// store the SSL configuration now
// once we call finished(), we won't have access to httpReply anymore
QSslConfiguration sslConfig = httpReply->sslConfiguration();
- if (pendingSslConfiguration)
+ if (pendingSslConfiguration) {
*pendingSslConfiguration = sslConfig;
- else if (!sslConfig.isNull())
- pendingSslConfiguration = new QSslConfiguration(sslConfig);
+ } else if (!sslConfig.isNull()) {
+ QT_TRY {
+ pendingSslConfiguration = new QSslConfiguration(sslConfig);
+ } QT_CATCH(...) {
+ qWarning("QNetworkAccess: could not allocate a QSslConfiguration object for a SSL connection.");
+ }
+ }
#endif
finished();
diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp
index bcbeef1..38e8af9 100644
--- a/src/network/access/qnetworkaccessmanager.cpp
+++ b/src/network/access/qnetworkaccessmanager.cpp
@@ -748,8 +748,8 @@ void QNetworkAccessManagerPrivate::createCookieJar() const
if (!cookieJarCreated) {
// keep the ugly hack in here
QNetworkAccessManagerPrivate *that = const_cast<QNetworkAccessManagerPrivate *>(this);
- that->cookieJarCreated = true;
that->cookieJar = new QNetworkCookieJar(that->q_func());
+ that->cookieJarCreated = true;
}
}
diff --git a/src/network/access/qnetworkdiskcache.cpp b/src/network/access/qnetworkdiskcache.cpp
index 44a8298..daa2335 100644
--- a/src/network/access/qnetworkdiskcache.cpp
+++ b/src/network/access/qnetworkdiskcache.cpp
@@ -43,6 +43,7 @@
#include "qnetworkdiskcache.h"
#include "qnetworkdiskcache_p.h"
+#include "QtCore/qscopedpointer.h"
#include <qfile.h>
#include <qdir.h>
@@ -180,8 +181,7 @@ QIODevice *QNetworkDiskCache::prepare(const QNetworkCacheMetaData &metaData)
break;
}
}
-
- QCacheItem *cacheItem = new QCacheItem;
+ QScopedPointer<QCacheItem> cacheItem(new QCacheItem);
cacheItem->metaData = metaData;
QIODevice *device = 0;
@@ -190,16 +190,20 @@ QIODevice *QNetworkDiskCache::prepare(const QNetworkCacheMetaData &metaData)
device = &(cacheItem->data);
} else {
QString templateName = d->tmpCacheFileName();
- cacheItem->file = new QTemporaryFile(templateName, &cacheItem->data);
- if (!cacheItem->file->open()) {
+ QT_TRY {
+ cacheItem->file = new QTemporaryFile(templateName, &cacheItem->data);
+ } QT_CATCH(...) {
+ cacheItem->file = 0;
+ }
+ if (!cacheItem->file || !cacheItem->file->open()) {
qWarning() << "QNetworkDiskCache::prepare() unable to open temporary file";
- delete cacheItem;
+ cacheItem.reset();
return 0;
}
cacheItem->writeHeader(cacheItem->file);
device = cacheItem->file;
}
- d->inserting[device] = cacheItem;
+ d->inserting[device] = cacheItem.take();
return device;
}
@@ -358,31 +362,28 @@ QIODevice *QNetworkDiskCache::data(const QUrl &url)
qDebug() << "QNetworkDiskCache::data()" << url;
#endif
Q_D(QNetworkDiskCache);
- QBuffer *buffer = 0;
+ QScopedPointer<QBuffer> buffer;
if (!url.isValid())
- return buffer;
+ return 0;
if (d->lastItem.metaData.url() == url && d->lastItem.data.isOpen()) {
- buffer = new QBuffer;
+ buffer.reset(new QBuffer);
buffer->setData(d->lastItem.data.data());
} else {
- QFile *file = new QFile(d->cacheFileName(url));
- if (!file->open(QFile::ReadOnly | QIODevice::Unbuffered)) {
- delete file;
+ QScopedPointer<QFile> file(new QFile(d->cacheFileName(url)));
+ if (!file->open(QFile::ReadOnly | QIODevice::Unbuffered))
return 0;
- }
- if (!d->lastItem.read(file, true)) {
+
+ if (!d->lastItem.read(file.data(), true)) {
file->close();
remove(url);
- delete file;
return 0;
}
if (d->lastItem.data.isOpen()) {
// compressed
- buffer = new QBuffer;
+ buffer.reset(new QBuffer);
buffer->setData(d->lastItem.data.data());
- delete file;
} else {
- buffer = new QBuffer;
+ buffer.reset(new QBuffer);
// ### verify that QFile uses the fd size and not the file name
qint64 size = file->size() - file->pos();
const uchar *p = 0;
@@ -390,16 +391,15 @@ QIODevice *QNetworkDiskCache::data(const QUrl &url)
p = file->map(file->pos(), size);
#endif
if (p) {
- file->setParent(buffer);
buffer->setData((const char *)p, size);
+ file.take()->setParent(buffer.data());
} else {
buffer->setData(file->readAll());
- delete file;
}
}
}
buffer->open(QBuffer::ReadOnly);
- return buffer;
+ return buffer.take();
}
/*!
diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp
index 4f9ea52..2ff561a 100644
--- a/src/network/access/qnetworkrequest.cpp
+++ b/src/network/access/qnetworkrequest.cpp
@@ -216,10 +216,9 @@ public:
url = other.url;
#ifndef QT_NO_OPENSSL
+ sslConfiguration = 0;
if (other.sslConfiguration)
sslConfiguration = new QSslConfiguration(*other.sslConfiguration);
- else
- sslConfiguration = 0;
#endif
}
diff --git a/src/network/kernel/qhostaddress.cpp b/src/network/kernel/qhostaddress.cpp
index b225c17..a3634ce 100644
--- a/src/network/kernel/qhostaddress.cpp
+++ b/src/network/kernel/qhostaddress.cpp
@@ -523,7 +523,7 @@ QHostAddress::QHostAddress(const struct sockaddr *sockaddr)
Constructs a copy of the given \a address.
*/
QHostAddress::QHostAddress(const QHostAddress &address)
- : d(new QHostAddressPrivate(*address.d))
+ : d(new QHostAddressPrivate(*address.d.data()))
{
}
@@ -559,7 +559,6 @@ QHostAddress::QHostAddress(SpecialAddress address)
*/
QHostAddress::~QHostAddress()
{
- delete d;
}
/*!
@@ -568,7 +567,7 @@ QHostAddress::~QHostAddress()
*/
QHostAddress &QHostAddress::operator=(const QHostAddress &address)
{
- *d = *address.d;
+ *d.data() = *address.d.data();
return *this;
}
diff --git a/src/network/kernel/qhostaddress.h b/src/network/kernel/qhostaddress.h
index 02a6f97..857b4af 100644
--- a/src/network/kernel/qhostaddress.h
+++ b/src/network/kernel/qhostaddress.h
@@ -44,6 +44,7 @@
#include <QtCore/qpair.h>
#include <QtCore/qstring.h>
+#include <QtCore/qscopedpointer.h>
#include <QtNetwork/qabstractsocket.h>
struct sockaddr;
@@ -130,7 +131,7 @@ public:
static QPair<QHostAddress, int> parseSubnet(const QString &subnet);
protected:
- QHostAddressPrivate *d;
+ QScopedPointer<QHostAddressPrivate> d;
};
inline bool operator ==(QHostAddress::SpecialAddress address1, const QHostAddress &address2)
diff --git a/src/network/kernel/qhostinfo.cpp b/src/network/kernel/qhostinfo.cpp
index ca4124d..1858e02 100644
--- a/src/network/kernel/qhostinfo.cpp
+++ b/src/network/kernel/qhostinfo.cpp
@@ -42,6 +42,7 @@
#include "qhostinfo.h"
#include "qhostinfo_p.h"
+#include "QtCore/qscopedpointer.h"
#include <qabstracteventdispatcher.h>
#include <private/qunicodetables_p.h>
#include <qcoreapplication.h>
@@ -165,24 +166,24 @@ int QHostInfo::lookupHost(const QString &name, QObject *receiver,
// Support for IDNA
QString lookup = QString::fromLatin1(QUrl::toAce(name));
- QHostInfoResult *result = new QHostInfoResult;
- result->autoDelete = false;
- QObject::connect(result, SIGNAL(resultsReady(QHostInfo)),
+ QScopedPointer<QHostInfoResult> result(new QHostInfoResult);
+ result.data()->autoDelete = false;
+ QObject::connect(result.data(), SIGNAL(resultsReady(QHostInfo)),
receiver, member);
- int id = result->lookupId = theIdCounter.fetchAndAddRelaxed(1);
+ int id = result.data()->lookupId = theIdCounter.fetchAndAddRelaxed(1);
if (lookup.isEmpty()) {
QHostInfo info(id);
info.setError(QHostInfo::HostNotFound);
info.setErrorString(QObject::tr("No host name given"));
- QMetaObject::invokeMethod(result, "emitResultsReady", Qt::QueuedConnection,
+ QMetaObject::invokeMethod(result.data(), "emitResultsReady", Qt::QueuedConnection,
Q_ARG(QHostInfo, info));
- result->autoDelete = true;
+ result.take()->autoDelete = true;
return id;
}
QHostInfoAgent *agent = theAgent();
- agent->addHostName(lookup, result);
+ agent->addHostName(lookup, result.take());
#if !defined QT_NO_THREAD
if (!agent->isRunning())
@@ -327,7 +328,7 @@ QHostInfo::QHostInfo(int id)
Constructs a copy of \a other.
*/
QHostInfo::QHostInfo(const QHostInfo &other)
- : d(new QHostInfoPrivate(*other.d))
+ : d(new QHostInfoPrivate(*other.d.data()))
{
}
@@ -337,7 +338,7 @@ QHostInfo::QHostInfo(const QHostInfo &other)
*/
QHostInfo &QHostInfo::operator=(const QHostInfo &other)
{
- *d = *other.d;
+ *d.data() = *other.d.data();
return *this;
}
@@ -346,7 +347,6 @@ QHostInfo &QHostInfo::operator=(const QHostInfo &other)
*/
QHostInfo::~QHostInfo()
{
- delete d;
}
/*!
diff --git a/src/network/kernel/qhostinfo.h b/src/network/kernel/qhostinfo.h
index 084ec89..c68b111 100644
--- a/src/network/kernel/qhostinfo.h
+++ b/src/network/kernel/qhostinfo.h
@@ -43,6 +43,7 @@
#define QHOSTINFO_H
#include <QtCore/qlist.h>
+#include <QtCore/qscopedpointer.h>
#include <QtNetwork/qhostaddress.h>
QT_BEGIN_HEADER
@@ -91,7 +92,7 @@ public:
static QString localDomainName();
private:
- QHostInfoPrivate *d;
+ QScopedPointer<QHostInfoPrivate> d;
};
QT_END_NAMESPACE
diff --git a/src/network/kernel/qhostinfo_unix.cpp b/src/network/kernel/qhostinfo_unix.cpp
index 3271deb..f5d7166 100644
--- a/src/network/kernel/qhostinfo_unix.cpp
+++ b/src/network/kernel/qhostinfo_unix.cpp
@@ -320,6 +320,8 @@ QString QHostInfo::localDomainName()
if (local_res_ninit) {
// using thread-safe version
res_state_ptr state = res_state_ptr(qMalloc(sizeof(*state)));
+ if (!state)
+ qBadAlloc();
memset(state, 0, sizeof(*state));
local_res_ninit(state);
QString domainName = QUrl::fromAce(state->defdname);
diff --git a/src/network/kernel/qnetworkinterface.cpp b/src/network/kernel/qnetworkinterface.cpp
index ff3624e..f8fff88 100644
--- a/src/network/kernel/qnetworkinterface.cpp
+++ b/src/network/kernel/qnetworkinterface.cpp
@@ -170,7 +170,7 @@ QNetworkAddressEntry::QNetworkAddressEntry()
object \a other.
*/
QNetworkAddressEntry::QNetworkAddressEntry(const QNetworkAddressEntry &other)
- : d(new QNetworkAddressEntryPrivate(*other.d))
+ : d(new QNetworkAddressEntryPrivate(*other.d.data()))
{
}
@@ -179,7 +179,7 @@ QNetworkAddressEntry::QNetworkAddressEntry(const QNetworkAddressEntry &other)
*/
QNetworkAddressEntry &QNetworkAddressEntry::operator=(const QNetworkAddressEntry &other)
{
- *d = *other.d;
+ *d.data() = *other.d.data();
return *this;
}
@@ -188,7 +188,6 @@ QNetworkAddressEntry &QNetworkAddressEntry::operator=(const QNetworkAddressEntry
*/
QNetworkAddressEntry::~QNetworkAddressEntry()
{
- delete d;
}
/*!
diff --git a/src/network/kernel/qnetworkinterface.h b/src/network/kernel/qnetworkinterface.h
index 09fbd0f..dd16550 100644
--- a/src/network/kernel/qnetworkinterface.h
+++ b/src/network/kernel/qnetworkinterface.h
@@ -43,6 +43,7 @@
#define QNETWORKINTERFACE_H
#include <QtCore/qshareddata.h>
+#include <QtCore/qscopedpointer.h>
#include <QtNetwork/qhostaddress.h>
#ifndef QT_NO_NETWORKINTERFACE
@@ -79,7 +80,7 @@ public:
void setBroadcast(const QHostAddress &newBroadcast);
private:
- QNetworkAddressEntryPrivate *d;
+ QScopedPointer<QNetworkAddressEntryPrivate> d;
};
class QNetworkInterfacePrivate;
diff --git a/src/network/kernel/qnetworkinterface_win.cpp b/src/network/kernel/qnetworkinterface_win.cpp
index de97629..c783c33 100644
--- a/src/network/kernel/qnetworkinterface_win.cpp
+++ b/src/network/kernel/qnetworkinterface_win.cpp
@@ -115,6 +115,8 @@ static QHash<QHostAddress, QHostAddress> ipv4Netmasks()
if (retval == ERROR_BUFFER_OVERFLOW) {
// need more memory
pAdapter = (IP_ADAPTER_INFO *)qMalloc(bufSize);
+ if (!pAdapter)
+ return ipv4netmasks;
// try again
if (ptrGetAdaptersInfo(pAdapter, &bufSize) != ERROR_SUCCESS) {
qFree(pAdapter);
@@ -156,7 +158,8 @@ static QList<QNetworkInterfacePrivate *> interfaceListingWinXP()
if (retval == ERROR_BUFFER_OVERFLOW) {
// need more memory
pAdapter = (IP_ADAPTER_ADDRESSES *)qMalloc(bufSize);
-
+ if (!pAdapter)
+ return interfaces;
// try again
if (ptrGetAdaptersAddresses(AF_UNSPEC, flags, NULL, pAdapter, &bufSize) != ERROR_SUCCESS) {
qFree(pAdapter);
@@ -236,7 +239,8 @@ static QList<QNetworkInterfacePrivate *> interfaceListingWin2k()
if (retval == ERROR_BUFFER_OVERFLOW) {
// need more memory
pAdapter = (IP_ADAPTER_INFO *)qMalloc(bufSize);
-
+ if (!pAdapter)
+ return interfaces;
// try again
if (ptrGetAdaptersInfo(pAdapter, &bufSize) != ERROR_SUCCESS) {
qFree(pAdapter);
@@ -306,7 +310,8 @@ QString QHostInfo::localDomainName()
pinfo = &info;
if (ptrGetNetworkParams(pinfo, &bufSize) == ERROR_BUFFER_OVERFLOW) {
pinfo = (FIXED_INFO *)qMalloc(bufSize);
-
+ if (!pinfo)
+ return QString();
// try again
if (ptrGetNetworkParams(pinfo, &bufSize) != ERROR_SUCCESS) {
qFree(pinfo);
diff --git a/src/network/socket/qlocalsocket_unix.cpp b/src/network/socket/qlocalsocket_unix.cpp
index 9e3cbde..03723cf 100644
--- a/src/network/socket/qlocalsocket_unix.cpp
+++ b/src/network/socket/qlocalsocket_unix.cpp
@@ -305,7 +305,7 @@ void QLocalSocketPrivate::_q_connectToSocket()
case EAGAIN:
// Try again later, all of the sockets listening are full
if (!delayConnect) {
- delayConnect = new QSocketNotifier(connectingSocket, QSocketNotifier::Write);
+ delayConnect = new QSocketNotifier(connectingSocket, QSocketNotifier::Write, q);
q->connect(delayConnect, SIGNAL(activated(int)), q, SLOT(_q_connectToSocket()));
}
if (!connectTimer) {
diff --git a/src/network/socket/qsocks5socketengine.cpp b/src/network/socket/qsocks5socketengine.cpp
index b6b0e89..98666c2 100644
--- a/src/network/socket/qsocks5socketengine.cpp
+++ b/src/network/socket/qsocks5socketengine.cpp
@@ -1834,9 +1834,9 @@ QSocks5SocketEngineHandler::createSocketEngine(QAbstractSocket::SocketType socke
QSOCKS5_DEBUG << "not proxying";
return 0;
}
- QSocks5SocketEngine *engine = new QSocks5SocketEngine(parent);
+ QScopedPointer<QSocks5SocketEngine> engine(new QSocks5SocketEngine(parent));
engine->setProxy(proxy);
- return engine;
+ return engine.take();
}
QAbstractSocketEngine *QSocks5SocketEngineHandler::createSocketEngine(int socketDescriptor, QObject *parent)
diff --git a/src/network/socket/qtcpserver.cpp b/src/network/socket/qtcpserver.cpp
index c1fedc3..1978ee2 100644
--- a/src/network/socket/qtcpserver.cpp
+++ b/src/network/socket/qtcpserver.cpp
@@ -354,7 +354,12 @@ void QTcpServer::close()
if (d->socketEngine) {
d->socketEngine->close();
- d->socketEngine->deleteLater();
+ QT_TRY {
+ d->socketEngine->deleteLater();
+ } QT_CATCH(const std::bad_alloc &) {
+ // in out of memory situations, the socketEngine
+ // will be deleted in ~QTcpServer (it's a child-object of this)
+ }
d->socketEngine = 0;
}
diff --git a/src/network/ssl/qsslcertificate.cpp b/src/network/ssl/qsslcertificate.cpp
index 7b554dc..c4aa43e 100644
--- a/src/network/ssl/qsslcertificate.cpp
+++ b/src/network/ssl/qsslcertificate.cpp
@@ -155,7 +155,7 @@ QSslCertificate::QSslCertificate(const QByteArray &data, QSsl::EncodingFormat fo
/*!
Constructs an identical copy of \a other.
*/
-QSslCertificate::QSslCertificate(const QSslCertificate &other) : d(other.d)
+QSslCertificate::QSslCertificate(const QSslCertificate &other) : d(other.d.data())
{
d->ref.ref();
}
@@ -165,8 +165,6 @@ QSslCertificate::QSslCertificate(const QSslCertificate &other) : d(other.d)
*/
QSslCertificate::~QSslCertificate()
{
- if (!d->ref.deref())
- delete d;
}
/*!
@@ -175,7 +173,7 @@ QSslCertificate::~QSslCertificate()
*/
QSslCertificate &QSslCertificate::operator=(const QSslCertificate &other)
{
- qAtomicAssign(d, other.d);
+ d.assign(other.d.data());
return *this;
}
@@ -241,12 +239,7 @@ void QSslCertificate::clear()
{
if (isNull())
return;
- if (d->ref == 1)
- delete d;
- else
- d->ref.deref();
-
- d = new QSslCertificatePrivate;
+ d.reset(new QSslCertificatePrivate);
}
/*!
diff --git a/src/network/ssl/qsslcertificate.h b/src/network/ssl/qsslcertificate.h
index d4597cd..19152fb 100644
--- a/src/network/ssl/qsslcertificate.h
+++ b/src/network/ssl/qsslcertificate.h
@@ -118,7 +118,7 @@ public:
Qt::HANDLE handle() const;
private:
- QSslCertificatePrivate *d;
+ QScopedSharedPointer<QSslCertificatePrivate> d;
friend class QSslCertificatePrivate;
friend class QSslSocketBackendPrivate;
};
diff --git a/src/network/ssl/qsslcipher.cpp b/src/network/ssl/qsslcipher.cpp
index 7fec2df..a72879d 100644
--- a/src/network/ssl/qsslcipher.cpp
+++ b/src/network/ssl/qsslcipher.cpp
@@ -103,7 +103,7 @@ QSslCipher::QSslCipher(const QString &name, QSsl::SslProtocol protocol)
QSslCipher::QSslCipher(const QSslCipher &other)
: d(new QSslCipherPrivate)
{
- *d = *other.d;
+ *d.data() = *other.d.data();
}
/*!
@@ -111,7 +111,6 @@ QSslCipher::QSslCipher(const QSslCipher &other)
*/
QSslCipher::~QSslCipher()
{
- delete d;
}
/*!
@@ -120,7 +119,7 @@ QSslCipher::~QSslCipher()
*/
QSslCipher &QSslCipher::operator=(const QSslCipher &other)
{
- *d = *other.d;
+ *d.data() = *other.d.data();
return *this;
}
diff --git a/src/network/ssl/qsslcipher.h b/src/network/ssl/qsslcipher.h
index 404dc3d..d9ac7a9 100644
--- a/src/network/ssl/qsslcipher.h
+++ b/src/network/ssl/qsslcipher.h
@@ -44,6 +44,7 @@
#define QSSLCIPHER_H
#include <QtCore/qstring.h>
+#include <QtCore/qscopedpointer.h>
#include <QtNetwork/qssl.h>
QT_BEGIN_HEADER
@@ -78,7 +79,7 @@ public:
QSsl::SslProtocol protocol() const;
private:
- QSslCipherPrivate *d;
+ QScopedPointer<QSslCipherPrivate> d;
friend class QSslSocketBackendPrivate;
};
diff --git a/src/network/ssl/qsslerror.cpp b/src/network/ssl/qsslerror.cpp
index 3096fee..280c659 100644
--- a/src/network/ssl/qsslerror.cpp
+++ b/src/network/ssl/qsslerror.cpp
@@ -140,7 +140,7 @@ QSslError::QSslError(SslError error, const QSslCertificate &certificate)
QSslError::QSslError(const QSslError &other)
: d(new QSslErrorPrivate)
{
- *d = *other.d;
+ *d.data() = *other.d.data();
}
/*!
@@ -148,7 +148,6 @@ QSslError::QSslError(const QSslError &other)
*/
QSslError::~QSslError()
{
- delete d;
}
/*!
@@ -158,7 +157,7 @@ QSslError::~QSslError()
*/
QSslError &QSslError::operator=(const QSslError &other)
{
- *d = *other.d;
+ *d.data() = *other.d.data();
return *this;
}
diff --git a/src/network/ssl/qsslerror.h b/src/network/ssl/qsslerror.h
index 50cc142..8b8ebff 100644
--- a/src/network/ssl/qsslerror.h
+++ b/src/network/ssl/qsslerror.h
@@ -105,7 +105,7 @@ public:
QSslCertificate certificate() const;
private:
- QSslErrorPrivate *d;
+ QScopedPointer<QSslErrorPrivate> d;
};
#ifndef QT_NO_DEBUG_STREAM
diff --git a/src/network/ssl/qsslkey.cpp b/src/network/ssl/qsslkey.cpp
index 8d550c0..d076112 100644
--- a/src/network/ssl/qsslkey.cpp
+++ b/src/network/ssl/qsslkey.cpp
@@ -269,7 +269,7 @@ QSslKey::QSslKey(QIODevice *device, QSsl::KeyAlgorithm algorithm, QSsl::Encoding
/*!
Constructs an identical copy of \a other.
*/
-QSslKey::QSslKey(const QSslKey &other) : d(other.d)
+QSslKey::QSslKey(const QSslKey &other) : d(other.d.data())
{
d->ref.ref();
}
@@ -279,8 +279,6 @@ QSslKey::QSslKey(const QSslKey &other) : d(other.d)
*/
QSslKey::~QSslKey()
{
- if (!d->ref.deref())
- delete d;
}
/*!
@@ -291,7 +289,7 @@ QSslKey::~QSslKey()
*/
QSslKey &QSslKey::operator=(const QSslKey &other)
{
- qAtomicAssign(d, other.d);
+ d.assign(other.d.data());
return *this;
}
@@ -312,10 +310,13 @@ bool QSslKey::isNull() const
*/
void QSslKey::clear()
{
- if (!d->ref.deref()) {
- delete d;
- d = new QSslKeyPrivate;
- }
+ d.reset(new QSslKeyPrivate);
+
+ //### old code: is this really correct???
+ //if (!d->ref.deref()) {
+ // delete d;
+ // d = new QSslKeyPrivate;
+ //}
}
/*!
diff --git a/src/network/ssl/qsslkey.h b/src/network/ssl/qsslkey.h
index 45d03f7..d5d60a6 100644
--- a/src/network/ssl/qsslkey.h
+++ b/src/network/ssl/qsslkey.h
@@ -45,6 +45,7 @@
#include <QtCore/qnamespace.h>
#include <QtCore/qbytearray.h>
+#include <QtCore/qscopedpointer.h>
#include <QtNetwork/qssl.h>
QT_BEGIN_HEADER
@@ -92,7 +93,7 @@ public:
inline bool operator!=(const QSslKey &key) const { return !operator==(key); }
private:
- QSslKeyPrivate *d;
+ QScopedSharedPointer<QSslKeyPrivate> d;
friend class QSslCertificate;
};