possible memory leak in DcmSegmentation::loadDataset

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
brister
Posts: 5
Joined: Mon, 2016-11-14, 09:48

possible memory leak in DcmSegmentation::loadDataset

#1 Post by brister »

Hello,

Valgrind is giving me a memory leak when I call DcmSegmentation::loadDataset. Here is the output from "valgrind --leak-check=full".
==18910== 954,134 (1,944 direct, 952,190 indirect) bytes in 1 blocks are definitely lost in loss record 1,522 of 1,522
==18910== at 0x4C2E0EF: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==18910== by 0x603D3A9: DcmSegmentation::loadDataset(DcmDataset&, DcmSegmentation*&) (in /usr/lib/libdcmseg.so.3.6.1.abi2)
This is on DCMTK version v3.6.1, 2015-09-24, running on Ubuntu 16.04. Here is the relevant code:

Code: Select all

        DcmFileFormat fileFormat;
        const char *dsoPath = dso.name();
        OFCondition status = fileFormat.loadFile(path);
        DcmDataset *dso_data = fileFormat.getDataset();

        // Initialize the DcmSegmentation object
        DcmSegmentation *dcmSegmentation;
        status = DcmSegmentation::loadDataset(*dso_data, dcmSegmentation);

It seems that something is not being freed when the calling function returns and the fileFormat destructor is called. Could this be the cause of the leak? If so, is there some other way to use dcmSegmentation that avoids the leak?

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: possible memory leak in DcmSegmentation::loadDataset

#2 Post by J. Riesmeier »

First of all, I would suggest that you use the latest DCMTK snapshot, which is from November this year. Then, maybe it's a silly question, but: Did you delete "dcmSegmentation" at the end of your program?

Jan Schlamelcher
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 318
Joined: Mon, 2014-03-03, 09:51
Location: Oldenburg, Germany

Re: possible memory leak in DcmSegmentation::loadDataset

#3 Post by Jan Schlamelcher »

I would recommend this (or something similar):

Code: Select all

...
OFunique_ptr<DcmSegmentation> dcmSegmentation;
{
  DcmSegmentation *t;
  status = DcmSegmentation::loadDataset(*dso_data, t);
  dcmSegmentation.reset(t);
}

brister
Posts: 5
Joined: Mon, 2016-11-14, 09:48

Re: possible memory leak in DcmSegmentation::loadDataset

#4 Post by brister »

Thanks, this resolves the issue. I was not aware that I had to delete the DcmSegmentation object.

Post Reply

Who is online

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