Memory Leak when using 'DcmFileFormat' read()

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
vignesh
Posts: 9
Joined: Mon, 2020-01-20, 11:44

Memory Leak when using 'DcmFileFormat' read()

#1 Post by vignesh »

Hi

I'm Using DCMTK-3.6.6
i have used DcmInputBufferStream for dcm file read. read buffer stream using DcmFileFormat. then save as dcm file.

here the sample code

Code: Select all

						DcmInputBufferStream buffer_stream();
						std::string outfilename = "E:\\tmp\\New\\test.dcm";
						DcmFileFormat fileformat;
						DcmInputBufferStream dcmStream;
						dcmStream.setBuffer((void*)buffer, file_size);
						dcmStream.setEos();
						fileformat.transferInit();
						OFCondition status = fileformat.read(dcmStream, EXS_Unknown, EGL_noChange);  // when i commented this line there are no memory leak 
						dcmStream.releaseBuffer();
						if (status.good())
						{
							DcmDataset *dataset = fileformat.getDataset();
							dataset->read(dcmStream, EXS_LittleEndianImplicit);
							auto xfer = dataset->getOriginalXfer();
							auto status = fileformat.saveFile(outfilename.c_str(), xfer, EET_ExplicitLength, EGL_recalcGL, EPD_withoutPadding, 0, 0, EWM_fileformat);
							if (status.good())
								LINFO("Image saved Successfully: " << outfilename);
							else
							{
								LERROR("Could Not Write DICOM File." << status.text());
							}
							dataset->clear();
						}
						fileformat.transferEnd();
						fileformat.clear();

i have used 500MB dicom file. after saving the dicom file around 7 to 10 MB memory not clearing. if i try another time it will take another 7 to 10 MB will be increased.

can you please let me know what i have missed in my code
Last edited by vignesh on Mon, 2023-06-12, 11:54, edited 1 time in total.

Michael Onken
DCMTK Developer
Posts: 2051
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: Memory Leak when using 'DcmFileFormat' read()

#2 Post by Michael Onken »

Hi,

I cannot see this from the snippet you provided (One guess: don't you have to allocate and free the "buffer" yourself?). But the best way to solve this yourself is to write a minimal test program and to throw into a memory checker like valgrind.

Best regards,
Michael

vignesh
Posts: 9
Joined: Mon, 2020-01-20, 11:44

Re: Memory Leak when using 'DcmFileFormat' read()

#3 Post by vignesh »

Hi,
Thanks for your response.

Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 1 guest