DicomImage::processNextFrames() causes memory leak

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
takeos
Posts: 16
Joined: Thu, 2008-12-18, 03:26
Location: Japan

DicomImage::processNextFrames() causes memory leak

#1 Post by takeos »

When a DicomImage instance is constructed for a MONOCHROME2 image, DiOverlay instance is also created as below.

Code: Select all

DiOverlay::DiOverlay(const DiDocument * docu=0x03d41748, const unsigned short alloc=8, const unsigned short stored=8, const unsigned short high=7)  line 70
DiMonoImage::Init(DiMonoModality * modality=0x03d3f6e8)  line 669 + 0x4a bytes
DiMonoImage::DiMonoImage(const DiDocument * docu=0x03d41748, EI_Status status=EIS_Normal)  line 103
DiMono2Image::DiMono2Image(const DiDocument * docu=0x03d41748, EI_Status status=EIS_Normal)  line 48 + 0x3d bytes
DicomImage::Init()  line 241 + 0x3c bytes
DicomImage::DicomImage(DcmObject * object=0x03d414d8, E_TransferSyntax xfer=EXS_LittleEndianExplicit, const unsigned long flags=1025, const unsigned long fstart=0, const unsigned long fcount=1)  line 106
Subsequent processNextFrames() call creates another DiOverlay instance as below, but the first one is not deleted since removeReference() is not called for Overlays[0] in DiMonoImage::Init() before assigning a new pointer to it.

Code: Select all

DiOverlay::DiOverlay(const DiDocument * docu=0x03d41748, const unsigned short alloc=8, const unsigned short stored=8, const unsigned short high=7)  line 70
DiMonoImage::Init(DiMonoModality * modality=0x03d3f6e8)  line 669 + 0x4a bytes
DiMonoImage::processNextFrames(const unsigned long fcount=1)  line 657
DicomImage::processNextFrames(const unsigned long fcount=1)  line 184 + 0x22 bytes

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

#2 Post by Michael Onken »

Hi,

thanks for the report. I'm not sure if just deleting and then creating a new one is the best way to solve that issue in DiMonoImage::Init(), like this:

Code: Select all

   if (modality != NULL)
    {
        // cleanup old data for builtin overlays (may be existing from previous frame processed)
        if (Overlays[0] != NULL)
            delete Overlays[0];
        Overlays[0] = new DiOverlay(Document, BitsAllocated, BitsStored, HighBit);
because I'm not sure what should/must be re-used etc. So I will wait for Jörg being the author to fix it (currently not in office). We will post here when we fixed that in the source code repository.

Best regards,
Michael

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

#3 Post by Jörg Riesmeier »

Thanks again for the report. Should be fixed now.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest