summaryrefslogtreecommitdiffstats
path: root/src/network/access
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/access')
-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
9 files changed, 48 insertions, 37 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
}