Bug 381583

Summary: potential crash in KDirWatch::~KDirWatch()
Product: [Frameworks and Libraries] frameworks-kcoreaddons Reporter: RJVB <rjvbertin>
Component: generalAssignee: Michael Pyne <mpyne>
Status: RESOLVED FIXED    
Severity: normal CC: aspotashev, faure, kdelibs-bugs
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Compiled Sources   
OS: All   
Latest Commit: Version Fixed In: 5.37
Attachments: check the d_ptr before using it

Description RJVB 2017-06-23 15:26:18 UTC
Created attachment 106264 [details]
check the d_ptr before using it

The KDirWatch dtor assumes that it always has a KDirWatchPrivate instance, an assumption not shared by (most of) the other class methods. I stumbled upon this during what could be called foolproofing (testing plasmoid with plasmawindowed outside of a running Plasma5 environment).
Comment 1 Michael Pyne 2017-06-24 02:11:02 UTC
I think this makes sense.  Seems to me that the current code could lead to a crash if the KDirWatch qPostRoutine were called (this nullifies the d-ptr) followed by the KDirWatch itself being destructed.  David, any thoughts on whether there's a better way to handle this?
Comment 2 David Faure 2017-07-08 13:40:27 UTC
This patch looks fine, please push it.
Comment 3 Michael Pyne 2017-07-08 19:01:15 UTC
Git commit b8cb28bcd0709a0ff49ac1ae40c0f44e7ea36f33 by Michael Pyne, on behalf of René J.V. Bertin.
Committed on 08/07/2017 at 19:00.
Pushed by mpyne into branch 'master'.

kdirwatch: Avoid potential crash if d-ptr destroyed before KDirWatch.

Found in a code review and patch proposed by René, although we've not
actually gone so far as to create a test case that forces a crash.

Committed by mpyne to get the bug closed out.
FIXED-IN:5.37

M  +1    -1    src/lib/io/kdirwatch.cpp

https://commits.kde.org/kcoreaddons/b8cb28bcd0709a0ff49ac1ae40c0f44e7ea36f33
Comment 4 Michael Pyne 2017-08-06 21:13:31 UTC
*** Bug 368278 has been marked as a duplicate of this bug. ***