Opening multiple DICOM series from one directory can result in a segfault
About you
CamiTK developer
Overview
When opening a DICOM directory, selecting multiple series to open sometimes crashes the software (segfault)
Steps to Reproduce
Unfortunately I cannot share (yet) the data used to test. In this DICOM directories, multiple series have the exact same name. After launching camitk-imp, opening the directory and selecting two series (for example Axial and Coronal T2 acquisitions) will result in a crash.
Actual VS Expected Result
Multiple Components should be loaded without crashing.
Relevant logs and/or screenshots
From the debugger:
#4 0x00007fffe41f0f71 in DicomSeries::getStudyName() const () from /home/bhattacm/Datas/prog/CamiTK2/build/lib/camitk-5.1/components/libdicom.so.5.1.dev
#5 0x00007fffe41e7ca9 in DicomComponentExtension::open(QString const&) () from /home/bhattacm/Datas/prog/CamiTK2/build/lib/camitk-5.1/components/libdicom.so.5.1.dev
#6 0x00007ffff7d2c7fa in camitk::Application::openDirectory (dirName=..., pluginName=...)
Interpretation & Possible fixes
There may be three problems with the following code in DicomComponentExtension.cpp
// Open each selected Dicom as a component
if (!seriesDialogEntries.isEmpty()) {
foreach (DicomDialogEntry* entry, seriesDialogEntries) {
// Find the corresponding Dicom Series in the List
foreach (DicomSeries* series, seriesParsed) {
if ((series->getStudyName() == entry->getStudyName()) &&
(series->getSeriesName() == entry->getSeriesName())) {
lastOpenedComponent = new DicomComponent(series);
break;
}
else {
delete series;
}
}
}
}
- The selected study is identified by name, and not ID. If two series have the same name, the first one will be loaded (may not be the correct one)
- "delete series;" statement will delete series that do not match the chosen serie's name until the chosen series is found. The series following this one will not be deleted (memory leak)
- if multiple series are selected, the outer loop will execute the inner loop a second time. At that point, some series are already deleted but the inner loop will call getStudyName and getSeriesName on them if they happen to be before the selected series in the seriesParsed list. This causes the segfault.
Proposed solutions:
- delete all series after the loops, not some of them (except if the series object is still stored somewhere in the DicomComponent)
- Try to use the series ID to find out which image was selected to avoid relying on the name which might not be unique
CamiTK Version
CamiTK 5.1.dev.develop.c3d59664
please do not remove anything below this line
Edited by Manik Bhattacharjee