https://bugs.kde.org/show_bug.cgi?id=527694

            Bug ID: 527694
           Summary: Test management crashes with CMake (and possibly
                    meson?) projects
    Classification: Applications
           Product: kdevelop
      Version First 6.6.260802
       Reported In:
          Platform: Compiled Sources
                OS: Linux
            Status: REPORTED
          Severity: crash
          Priority: NOR
         Component: Build tools: CMake
          Assignee: [email protected]
          Reporter: [email protected]
  Target Milestone: ---

DESCRIPTION
Tests with duplicate names cause an ownership conflict in KDevelop that results
in the CMake plugin holding a pointer to freed memory.

STEPS TO REPRODUCE
0. Use an instrumented KDevelop
1. Open the minimal reproducer project (see below) 
2. Reload the project (may need to repeat)

OBSERVED RESULT
KDevelop crashes. Additionally, an instrumented build (see below) reveals that
a CTestSuite instance owned by CMakeManager gets freed without its knowledge,
resulting in a dangling pointer.

EXPECTED RESULT
KDevelop doesn't crash

SOFTWARE/OS VERSIONS
KDE Frameworks Version: 6.28.0
Qt Version: 6.11.1

ADDITIONAL INFORMATION
TestController::addTestSuite (shell) deletes a CTestSuite that was allocated by
CMakeManager. As a result, a CMakeManager::PerProjectData::testSuites now
contains a pointer to freed memory, and KDevelop is a bomb waiting to explode.
Actually triggering a crash may or may not be reliable, but instrumenting
construction of CTestSuite instances and deletion via
TestController::addTestSuite readily confirms that KDevelop enters this
dangerous state. In my experience, this *often* leads to a crash when KDevelop
reparses the project, e.g., when making changes to the CMake logic, as this
triggers a reload/reparse. Reloading the project manually acts as a shortcut.
(Rebuilding KDevelop with asan, or even just running under valgrind, will
greatly improve the chances of the error being detected and causing an abort.)

This appears to be caused by the existence of multiple tests with the same name
in the same project. Which I can confirm from my instrumentation:
allocate 0x7c55020f79e0 "collision" in "bad-test"
allocate 0x7c55020f7cb0 "collision" in "bad-test"
shell: free 0x7c55020f79e0

...and when reloading the project:
cmake: free 0x7c55020f79e0 <= this won't end well

Claude was used to help track this down, but I have personally verified that
all information in this report is correct. Claude thinks Meson might have a
similar issue, but I did not verify that claim.

Here is the minimal reproducer used above:

==> CMakeLists.txt <==
cmake_minimum_required(VERSION 4.0)
project(bad-test)
enable_testing()

add_subdirectory(a)
add_subdirectory(b)

==> a/CMakeLists.txt <==
add_test(NAME collision COMMAND /bin/true)

==> b/CMakeLists.txt <==
add_test(NAME collision COMMAND /bin/true)

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to