# Segfault when calling destructor on ctkDICOMIndexer and ctkDICOMDatabase

**URL:** <https://discourse.slicer.org/t/segfault-when-calling-destructor-on-ctkdicomindexer-and-ctkdicomdatabase/12653>\
**Category:** Development\
**Created:** [July 21, 2020, 12:07am UTC](https://discourse.slicer.org/t/segfault-when-calling-destructor-on-ctkdicomindexer-and-ctkdicomdatabase/12653 "2020-07-21T00:07:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jakew](https://avatars.discourse-cdn.com/v4/letter/j/4af34b/32.png) [@Jakew](https://discourse.slicer.org/u/Jakew)\
**Post date:** [July 21, 2020, 12:07am UTC](https://discourse.slicer.org/t/segfault-when-calling-destructor-on-ctkdicomindexer-and-ctkdicomdatabase/12653/1 "2020-07-21T00:07:40Z")

</div>

I am working on a loadable module extension in which I create a new ctkDICOMIndexer object and a new ctkDICOMDatabase, which I delete in the extension’s destructor. However, when I quit my application, a segfault occurs. I’ve identified that it occurs in the file ctkDICOMIndexer.cpp file in the line “QObject::disconnect(d-\>Database, SIGNAL(opened()), this, SLOT(databaseFilenameChanged()));”  
Does anyone know what the problem could be?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 23, 2020, 2:00am UTC](https://discourse.slicer.org/t/segfault-when-calling-destructor-on-ctkdicomindexer-and-ctkdicomdatabase/12653/2 "2020-07-23T02:00:31Z")

</div>

Probably when you deleted the database then you forget to set `d->Database` to nullptr. Dereferencing a dangling pointer (using then `d->Database` after the object is deleted) will cause a segfault. The solution is to set the pointer to nullptr (or use some type of smart pointer) and only disconnect the database if it still exists.
