Fix segfault on project reload with cmake
AbandonedPublic

Authored by mwolff on Oct 2 2018, 3:02 PM.

Details

Reviewers
mkraus
Group Reviewers
KDevelop
Summary

When a project gets reloaded and a folder was added with a cmake option,
folder and file items are created and enqueued in FileManagerListJob.
Then all folder and file items get deleted and when the next
FileManagerListJob::startNextJob() accesses an element in the queue it's
a dangling pointer and a segfault happens.

BUG: 398822

FIXED-IN: 3.0

Test Plan

Create a project like this. Only CMakeLists.txt really matters. The other files just have to be there and have valid code.

CMakeLists.txt like this

cmake_minimum_required(VERSION 3.5)
project(crash)

option(test "build tests" OFF)

add_library(crash
    source/lib.cpp
)

if(test)
    add_executable(unittest test/test.cpp)
endif(test)

source/lib.cpp

int add(int a, int b) {
    return a + b;
}

test/test.cpp

int main() {
    return 0;
}

Proceed this steps:

  1. Project -> Prune Selection
  2. Project -> Configure Selection
  3. Project -> Open Configuration...
  4. Enable custom "test" cmake option
  5. Click on OK -> segfault without patch; no segfault with patch

Diff Detail

Repository
R32 KDevelop
Lint
Lint Skipped
Unit
Unit Tests Skipped
mkraus created this revision.Oct 2 2018, 3:02 PM
Restricted Application added a subscriber: kdevelop-devel. ยท View Herald TranscriptOct 2 2018, 3:02 PM
mkraus requested review of this revision.Oct 2 2018, 3:02 PM
mkraus edited the test plan for this revision. (Show Details)Oct 2 2018, 3:06 PM
mkraus edited the summary of this revision. (Show Details)
mkraus edited the test plan for this revision. (Show Details)
nicolasfella retitled this revision from Fiix segfalut on project reload with cmake to Fix segfault on project reload with cmake.Oct 2 2018, 4:01 PM
apol added a subscriber: apol.Oct 3 2018, 5:09 PM

Would it make sense to recreate the KDirWatchers at this point? I would prefer if this patch didn't have to get outside the plugin.

mkraus added a comment.Oct 9 2018, 8:09 PM
In D15899#336024, @apol wrote:

Would it make sense to recreate the KDirWatchers at this point? I would prefer if this patch didn't have to get outside the plugin.

Was this question directed to me? If yes, I'm not familiar enough with the code to have a knowledgeable answer.

How to proceed?

apol added a comment.Nov 29 2018, 4:04 PM

Hi, sorry it took me such longtime to answer.
I've been trying to reproduce the issue and I've been sadly unable to reproduce it.
Can you still reproduce?

In general, the folders shouldn't need re-creation since they're always there, it's just the target, and the target is not dealt with by the FileManager bit. Am I missing something?

Don't worry, no problem.

I can still reproduce the crash on two machines I have access to. This seems to be a race. Items are added to a queue in FileManagerListJob and deleted afterwards while still beeing in the queue. There is a more thorough description in the bug report.

Btw, I just tested with a release build.

mwolff requested changes to this revision.Jan 26 2019, 12:04 PM
mwolff added a subscriber: mwolff.

sorry for the long delay, I just tested this and I can reproduce the crash. But just like Aleix, I'm opposed to the suggested way of fixing it. The patch increases coupling without solving the underlying problem. To me, it looks like the list job simply must not store raw pointers, as that's inherently unsafe when we think about changes being done during the queued signal emission... I think to fix this properly, we need to refactor the listjob, and I have an idea on how to do that (operate on indexed strings instead of items, only lookup item when listjob has finished). I'll try this out now and get back to you afterwards.

This revision now requires changes to proceed.Jan 26 2019, 12:04 PM

No problem, I could work with my patch :)

I'm glad you could reproduce the bug. If there is something I can do to help you with the implementation let me know.

sadly my initial attempt doesn't work either ;-) I'm looking at this some more now and will let you know once I've found an alternative approach

mwolff commandeered this revision.Jan 26 2019, 10:28 PM
mwolff edited reviewers, added: mkraus; removed: mwolff.

finally got it working, man that old code was broken :D I wrote most of that a really long time ago, and it shows!

https://invent.kde.org/kde/kdevelop/merge_requests/4

I'll commandeer this request and close it then, we will continue the discussion on gitlab then.

mwolff abandoned this revision.Jan 26 2019, 10:29 PM