Crash when deleting a DcmFileFormat

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
Daanen
Posts: 27
Joined: Mon, 2008-03-17, 17:41

Crash when deleting a DcmFileFormat

#1 Post by Daanen »

Hi,

I have a class which is used to wrap DcmFileFormat. There are others methods but there are not of interest here.

Code: Select all

class CDicomFile
{
public:
	//! Constructeur
	CDicomFile() : m_pDcmDataset(NULL)
	{	m_pFileformat = new DcmFileFormat();};
	
	//! Destructeur
	virtual ~CDicomFile()
       {  delete m_pFileformat;};
	
protected :
	  // pointeur sur la structure DcmDataset interne
	  DcmDataset *m_pDcmDataset;
	  DcmFileFormat *m_pFileformat;
	  
};
I'm using pointer because when I used to use a variable, on the creation of the DcmFileFormat, software crashes deep inside dcmtk

Now, when I want to delete m_pFileformat in the dtor, I get a runtime error wirth these messages from the debugger

Code: Select all

>	main.exe!CheckBytes(unsigned char * pb=0x01442244, unsigned char bCheck='í', unsigned int nSize=3)  Ligne 1595 + 0x7 octets	C++
 	main.exe!_free_dbg_nolock(void * pUserData=0x01442248, int nBlockUse=1)  Ligne 1231 + 0x17 octets	C++
 	main.exe!_free_dbg(void * pUserData=0x01442248, int nBlockUse=1)  Ligne 1194 + 0xd octets	C++
 	main.exe!operator delete(void * p=0x01442248)  Ligne 373 + 0xb octets	C++
 	main.exe!operator delete[](void * p=0x01442248)  Ligne 387 + 0x9 octets	C++
 	main.exe!DcmElement::~DcmElement()  Ligne 171 + 0x12 octets	C++
 	main.exe!DcmOtherByteOtherWord::~DcmOtherByteOtherWord()  Ligne 68 + 0x8 octets	C++
 	main.exe!DcmPolymorphOBOW::~DcmPolymorphOBOW()  Ligne 59 + 0x8 octets	C++
 	main.exe!DcmPixelData::~DcmPixelData()  Ligne 150 + 0x1e octets	C++
 	main.exe!DcmPixelData::`scalar deleting destructor'()  + 0xf octets	C++
 	main.exe!DcmItem::~DcmItem()  Ligne 174 + 0x20 octets	C++
 	main.exe!DcmDataset::~DcmDataset()  Ligne 101 + 0x8 octets	C++
 	main.exe!DcmDataset::`scalar deleting destructor'()  + 0xf octets	C++
 	main.exe!DcmSequenceOfItems::~DcmSequenceOfItems()  Ligne 105 + 0x20 octets	C++
 	main.exe!DcmFileFormat::~DcmFileFormat()  Ligne 114 + 0x8 octets	C++
 	main.exe!DcmFileFormat::`scalar deleting destructor'()  + 0xf octets	C++
 	main.exe!CDicomFile::~CDicomFile()  Ligne 17 + 0x37 octets	C++
I compiled and installed the last available version (dcmtk3.5.4-20090602) but the problem is still there.

I try a solution which consist in not deleting m_pFileformat. It works but I do have memory leaks :(


Is it a know problem or is there a solution ?

Thx
vince

[/code]

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#2 Post by Jörg Riesmeier »

Something seems to be wrong with the pixel data element - as far as I can see. Are you sure that you are not deleting the pixel data twice?

Daanen
Posts: 27
Joined: Mon, 2008-03-17, 17:41

#3 Post by Daanen »

Jörg Riesmeier wrote:Something seems to be wrong with the pixel data element - as far as I can see. Are you sure that you are not deleting the pixel data twice?
Hi,

I just checked my source (which is posted below) and as you can see, I'm not deleting the pixel data even once

Code: Select all

	m_ErrCode=0;
	if (!LoadFromFile(p_DicomFilename))
	{
		m_ErrCode = LoadFailed;
		return false;
	}

	DcmTag tag(0x7fe1, 0x1002);
	DcmElement *tagValue;

	OFCondition resSearch = m_pDcmDataset->findAndGetElement(tag, tagValue,OFFalse);
	if (resSearch != EC_Normal)
	{
		m_ErrCode = TagNotFound;
		return false;
	}

	Uint8 *byteVals=NULL;
	resSearch = tagValue->getUint8Array(byteVals);
	if (resSearch != EC_Normal)
	{
		m_ErrCode = CouldNotExtractData;
		return false;
	}

	std::ofstream l_oFile;
	l_oFile.open(LPCTSTR(p_MvlFilename), std::ios::binary);
	if (!l_oFile.is_open())
	{
		m_ErrCode = CouldNotWriteOutputFile;
		return false;
	}

	l_oFile.write((char *)(byteVals), tagValue->getLength());
	l_oFile.close();
	
	return true;
V

PS : the method "LoadFromFile" is used to open the dicom file with dcmFileformat::loadFile, that's all ...

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#4 Post by Jörg Riesmeier »

Would be interesting to see what you are doing with m_pFileformat and m_pDcmDataset throughout your program.

Daanen
Posts: 27
Joined: Mon, 2008-03-17, 17:41

#5 Post by Daanen »

Hi,

CDicomFile is a base class for accessing Dicom data. Subclasses are accessing data such as PixelData, ImagePatientOrientation, ImagePatientPosition and so on.

In fine, I'm essentially using m_pDcmDataset to "find and get" element value.

Just to be sure: when using something like

Code: Select all

Uint8 *byteVals=NULL; 
resSearch = tagValue->getUint8Array(byteVals); 
it is not necessary to delete byteVals, am I right ?

V

PS : if you have an idea of anything to check in my source code, let me know, I'll have a look..

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest