Review Request 124253: Resurrect dead code and fix two memory leaks

Maxim Mikityanskiy maxtram95 at gmail.com
Sat Jul 4 17:34:17 BST 2015



> On Июль 4, 2015, 4:18 п.п., Kai Uwe Broulik wrote:
> > daemon/backends/upower/login1suspendjob.cpp, line 83
> > <https://git.reviewboard.kde.org/r/124253/diff/1/?file=383152#file383152line83>
> >
> >     If you're at it, please change this to the new connect syntax:
> >     
> >     connect(watcher, &QDBusPendingCallWatcher::finished, this, &Login1SuspendJob::sendResult);
> 
> Kai Uwe Broulik wrote:
>     Do you have commit access or should I push this on your behalf?

Fixed to use new connect syntax. No, I don't have commit access.


- Maxim


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://git.reviewboard.kde.org/r/124253/#review82073
-----------------------------------------------------------


On Июль 4, 2015, 4:32 п.п., Maxim Mikityanskiy wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://git.reviewboard.kde.org/r/124253/
> -----------------------------------------------------------
> 
> (Updated Июль 4, 2015, 4:32 п.п.)
> 
> 
> Review request for kde-workspace.
> 
> 
> Repository: powerdevil
> 
> 
> Description
> -------
> 
> 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.
> 
> ```c++
> 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.
> 
> 
> Diffs
> -----
> 
>   daemon/backends/upower/login1suspendjob.cpp 8918b22 
> 
> Diff: https://git.reviewboard.kde.org/r/124253/diff/
> 
> 
> Testing
> -------
> 
> 
> Thanks,
> 
> Maxim Mikityanskiy
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20150704/d7d22b21/attachment.htm>


More information about the kde-core-devel mailing list