From a437ede4249d29fc598e78ee414a64d28a774a41 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Tue, 5 Jun 2012 15:18:55 +0200 Subject: [PATCH] SSH: Fix some potential crashes. Change-Id: I102e35c3dcd3725f357c91d9f0a77ab28d881b0d Reviewed-by: Oliver Wolff Reviewed-by: Tim Jenssen --- src/libs/ssh/sshconnection.cpp | 6 +++--- src/libs/ssh/sshconnectionmanager.cpp | 2 +- src/plugins/remotelinux/linuxdevicetester.cpp | 11 +++++++---- .../remotelinux/remotelinuxusedportsgatherer.cpp | 1 + src/plugins/valgrind/valgrindprocess.cpp | 3 ++- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/libs/ssh/sshconnection.cpp b/src/libs/ssh/sshconnection.cpp index 2c3908920f8..c6a1151d59b 100644 --- a/src/libs/ssh/sshconnection.cpp +++ b/src/libs/ssh/sshconnection.cpp @@ -108,8 +108,10 @@ bool operator!=(const SshConnectionParameters &p1, const SshConnectionParameters // TODO: Mechanism for checking the host key. First connection to host: save, later: compare SshConnection::SshConnection(const SshConnectionParameters &serverInfo) - : d(new Internal::SshConnectionPrivate(this, serverInfo)) { + doStaticInitializationsIfNecessary(); + + d = new Internal::SshConnectionPrivate(this, serverInfo); connect(d, SIGNAL(connected()), this, SIGNAL(connected()), Qt::QueuedConnection); connect(d, SIGNAL(dataAvailable(QString)), this, @@ -202,8 +204,6 @@ SshConnectionPrivate::SshConnectionPrivate(SshConnection *conn, m_connParams(serverInfo), m_error(SshNoError), m_ignoreNextPacket(false), m_conn(conn) { - doStaticInitializationsIfNecessary(); - setupPacketHandlers(); m_socket->setProxy(m_connParams.proxyType == SshConnectionParameters::DefaultProxy ? QNetworkProxy::DefaultProxy : QNetworkProxy::NoProxy); diff --git a/src/libs/ssh/sshconnectionmanager.cpp b/src/libs/ssh/sshconnectionmanager.cpp index 46b37ef2147..114b5200867 100644 --- a/src/libs/ssh/sshconnectionmanager.cpp +++ b/src/libs/ssh/sshconnectionmanager.cpp @@ -154,7 +154,7 @@ public: if (doDelete) { disconnect(connection, 0, this, 0); m_deprecatedConnections.removeAll(connection); - delete connection; + connection->deleteLater(); } } diff --git a/src/plugins/remotelinux/linuxdevicetester.cpp b/src/plugins/remotelinux/linuxdevicetester.cpp index 7905c7b3347..222284cdb7c 100644 --- a/src/plugins/remotelinux/linuxdevicetester.cpp +++ b/src/plugins/remotelinux/linuxdevicetester.cpp @@ -76,7 +76,8 @@ GenericLinuxDeviceTester::GenericLinuxDeviceTester(QObject *parent) GenericLinuxDeviceTester::~GenericLinuxDeviceTester() { - delete d->connection; + if (d->connection) + d->connection->deleteLater(); delete d; } @@ -186,10 +187,12 @@ void GenericLinuxDeviceTester::handlePortListReady() void GenericLinuxDeviceTester::setFinished(TestResult result) { d->state = Inactive; - disconnect(d->connection, 0, this, 0); disconnect(&d->portsGatherer, 0, this, 0); - delete d->connection; - d->connection = 0; + if (d->connection) { + disconnect(d->connection, 0, this, 0); + d->connection->deleteLater(); + d->connection = 0; + } emit finished(result); } diff --git a/src/plugins/remotelinux/remotelinuxusedportsgatherer.cpp b/src/plugins/remotelinux/remotelinuxusedportsgatherer.cpp index 58a544150ad..1c30195856f 100644 --- a/src/plugins/remotelinux/remotelinuxusedportsgatherer.cpp +++ b/src/plugins/remotelinux/remotelinuxusedportsgatherer.cpp @@ -69,6 +69,7 @@ RemoteLinuxUsedPortsGatherer::RemoteLinuxUsedPortsGatherer(QObject *parent) : RemoteLinuxUsedPortsGatherer::~RemoteLinuxUsedPortsGatherer() { + stop(); delete d; } diff --git a/src/plugins/valgrind/valgrindprocess.cpp b/src/plugins/valgrind/valgrindprocess.cpp index c5cde6ff277..e805cc00e76 100644 --- a/src/plugins/valgrind/valgrindprocess.cpp +++ b/src/plugins/valgrind/valgrindprocess.cpp @@ -167,7 +167,8 @@ RemoteValgrindProcess::RemoteValgrindProcess(QSsh::SshConnection *connection, QO RemoteValgrindProcess::~RemoteValgrindProcess() { - delete m_connection; + if (m_connection) + m_connection->deleteLater(); } bool RemoteValgrindProcess::isRunning() const