[Insight-users] Cannot delete ITK objects

Dirk Boye body at nabla.org
Fri Oct 9 08:36:03 EDT 2009


Dear list,

When I'm trying to delete an ITK object I get a segmentation fault.

My minimum example test.cpp:

#include <itkImageFileReader.h>
#include <itkImage.h>
#include <itkImageFileReader.h>
#include <itkImageToVTKImageFilter.h>

#include <vtkImageData.h>

#include <cstdio>

typedef float                                   PixelType;
typedef itk::Image<PixelType, 3>  		ImageType;
typedef itk::ImageFileReader<ImageType>  	ReaderType;
typedef itk::ImageToVTKImageFilter<ImageType>   ConnectorType;

int main(int argc, char **argv){
	cout << "Test!" << endl;
 	ReaderType::Pointer readeritk = ReaderType::New();
 	readeritk->Delete();
 	vtkImageData *data=vtkImageData::New();
 	data->Delete();
}

The libraries I link:
TARGET_LINK_LIBRARIES ( test
  vtkImaging ITKIO ITKBasicFilters
  )

If I comment readeritk->Delete();
everything runs fine.

What am I missing here?

Backtrace:

dirk at dirk-pc:~/projects/test2$ ./test
Test!
*** glibc detected *** ./test: double free or corruption (top):
0x000000000137ea40 ***
======= Backtrace: =========
/lib/libc.so.6[0x7f1891e08cb8]
/lib/libc.so.6(cfree+0x76)[0x7f1891e0b276]
./test(_ZN3itk11LightObjectD0Ev+0x23e)[0x7b3c10]
./test(_ZNK3itk11LightObject10UnRegisterEv+0x48)[0x7b4112]
./test(_ZN3itk12SmartPointerINS_15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEEEE10UnRegisterEv+0x35)[0x4fd927]
./test(_ZN3itk12SmartPointerINS_15ImageFileReaderINS_5ImageIfLj3EEENS_25DefaultConvertPixelTraitsIfEEEEED1Ev+0x15)[0x4fd93f]
./test(main+0x58)[0x4fd414]
/lib/libc.so.6(__libc_start_main+0xe6)[0x7f1891daf5a6]
./test[0x4fd289]
======= Memory map: ========
00400000-00920000 r-xp 00000000 08:06 291453                            
/home/dirk/projects/test2/test
00b20000-00b22000 r--p 00520000 08:06 291453                            
/home/dirk/projects/test2/test
00b22000-00b4c000 rw-p 00522000 08:06 291453                            
/home/dirk/projects/test2/test
00b4c000-00b4e000 rw-p 00b4c000 00:00 0
012b3000-0139a000 rw-p 012b3000 00:00 0                                 
[heap]
7f188c000000-7f188c021000 rw-p 7f188c000000 00:00 0
7f188c021000-7f1890000000 ---p 7f188c021000 00:00 0
7f1891d91000-7f1891ef9000 r-xp 00000000 08:03 7719                      
/lib/libc-2.9.so
7f1891ef9000-7f18920f9000 ---p 00168000 08:03 7719                      
/lib/libc-2.9.so
7f18920f9000-7f18920fd000 r--p 00168000 08:03 7719                      
/lib/libc-2.9.so
7f18920fd000-7f18920fe000 rw-p 0016c000 08:03 7719                      
/lib/libc-2.9.so
7f18920fe000-7f1892103000 rw-p 7f18920fe000 00:00 0
7f1892103000-7f1892119000 r-xp 00000000 08:03 2587                      
/lib/libgcc_s.so.1
7f1892119000-7f1892319000 ---p 00016000 08:03 2587                      
/lib/libgcc_s.so.1
7f1892319000-7f189231a000 r--p 00016000 08:03 2587                      
/lib/libgcc_s.so.1
7f189231a000-7f189231b000 rw-p 00017000 08:03 2587                      
/lib/libgcc_s.so.1
7f189231b000-7f189240c000 r-xp 00000000 08:03 9958                      
/usr/lib/libstdc++.so.6.0.10
7f189240c000-7f189260c000 ---p 000f1000 08:03 9958                      
/usr/lib/libstdc++.so.6.0.10
7f189260c000-7f1892613000 r--p 000f1000 08:03 9958                      
/usr/lib/libstdc++.so.6.0.10
7f1892613000-7f1892615000 rw-p 000f8000 08:03 9958                      
/usr/lib/libstdc++.so.6.0.10
7f1892615000-7f1892628000 rw-p 7f1892615000 00:00 0
7f1892628000-7f189262a000 r-xp 00000000 08:03 7722                      
/lib/libdl-2.9.so
7f189262a000-7f189282a000 ---p 00002000 08:03 7722                      
/lib/libdl-2.9.so
7f189282a000-7f189282b000 r--p 00002000 08:03 7722                      
/lib/libdl-2.9.so
7f189282b000-7f189282c000 rw-p 00003000 08:03 7722                      
/lib/libdl-2.9.so
7f189282c000-7f18928b0000 r-xp 00000000 08:03 7723                      
/lib/libm-2.9.so
7f18928b0000-7f1892aaf000 ---p 00084000 08:03 7723                      
/lib/libm-2.9.so
7f1892aaf000-7f1892ab0000 r--p 00083000 08:03 7723                      
/lib/libm-2.9.so
7f1892ab0000-7f1892ab1000 rw-p 00084000 08:03 7723                      
/lib/libm-2.9.so
7f1892ab1000-7f1892ac8000 r-xp 00000000 08:03 7733                      
/lib/libpthread-2.9.so
7f1892ac8000-7f1892cc7000 ---p 00017000 08:03 7733                      
/lib/libpthread-2.9.so
7f1892cc7000-7f1892cc8000 r--p 00016000 08:03 7733                      
/lib/libpthread-2.9.so
7f1892cc8000-7f1892cc9000 rw-p 00017000 08:03 7733                      
/lib/libpthread-2.9.so
7f1892cc9000-7f1892ccd000 rw-p 7f1892cc9000 00:00 0
7f1892ccd000-7f1892cd0000 r-xp 00000000 08:03 2676                      
/lib/libuuid.so.1.2
7f1892cd0000-7f1892ed0000 ---p 00003000 08:03 2676                      
/lib/libuuid.so.1.2
7f1892ed0000-7f1892ed1000 r--p 00003000 08:03 2676                      
/lib/libuuid.so.1.2
7f1892ed1000-7f1892ed2000 rw-p 00004000 08:03 2676                      
/lib/libuuid.so.1.2
7f1892ed2000-7f1892ef2000 r-xp 00000000 08:03 7716                      
/lib/ld-2.9.so
7f18930cb000-7f18930cf000 rw-p 7f18930cb000 00:00 0
7f18930ed000-7f18930f1000 rw-p 7f18930ed000 00:00 0
7f18930f1000-7f18930f2000 r--p 0001f000 08:03 7716                      
/lib/ld-2.9.so
7f18930f2000-7f18930f3000 rw-p 00020000 08:03 7716                      
/lib/ld-2.9.so
7fff9b0de000-7fff9b0f3000 rw-p 7ffffffea000 00:00 0                     
[stack]
7fff9b1ff000-7fff9b200000 r-xp 7fff9b1ff000 00:00 0                     
[vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                 
[vsyscall]
Aborted


More information about the Insight-users mailing list