Resurrect dead code and fix two memory leaks

Review Request #124253 - Created July 4, 2015 and submitted

Maxim Mikityanskiy

At first, there is a memory leak when watcher is created in Login1SuspendJob::doStart, then switch goes through default branch, and the watcher is never deleted.

The second bug is more serious.

QDBusPendingReply<void> reply;
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(sendResult(QDBusPendingCallWatcher*)));

The above piece of code creates default-initialized reply, then creates watcher for this reply, and connects the signal to sendResult slot. But then, in every case branch of switch, reply gets overwritten. Old reply gets destroyed and new object assigns into that variable named reply. No watcher is bound with the new reply! So what we got: our watcher will never be deleted, and sendResult slot will never be called.

To fix that bugs we should create watcher for the real reply, not for default-initialized one. If no reply was created, don't create watcher, so avoid the first leak. If the reply was created, create watcher for it, so that sendResult will be called and watcher will be deleted from here.

This simple patch fixes described problems.



  • 0
  • 1
  • 0
  • 1
Description From Last Updated
Kai Uwe Broulik
Maxim Mikityanskiy
Maxim Mikityanskiy
Maxim Mikityanskiy
Review request changed

Status: Closed (submitted)

Change Summary:

Submitted with commit 0bda8dd05d52e22a989ca4e2fb948652cbdec4e7 by Kai Uwe Broulik on behalf of Maxim Mikityanskiy to branch master.