[Dcmlib] Amélioration des Memory leak

Jean-Michel Rouet jm.rouet at noos.fr
Tue Nov 16 21:54:01 CET 2004


Pour TestCopyDicom.cxx voici un petit patch qui devrait regler l'affaire:

rouet at vanoise:~/src/gdcm/Test$ cvs diff -u TestCopyDicom.cxx
Index: TestCopyDicom.cxx
===================================================================
RCS file: /cvs/public/gdcm/Test/TestCopyDicom.cxx,v
retrieving revision 1.16
diff -u -r1.16 TestCopyDicom.cxx
--- TestCopyDicom.cxx   16 Nov 2004 04:28:20 -0000      1.16
+++ TestCopyDicom.cxx   16 Nov 2004 20:51:07 -0000
@@ -91,6 +91,7 @@
       size_t dataSize = original->GetImageDataSize();
       uint8_t* imageData = original->GetImageData();

+
       //First of all copy the header field by field

       // Warning :Accessor gdcmElementSet::GetEntry() should not exist
@@ -105,8 +106,13 @@
          d = tag->second;
          if ( gdcm::BinEntry* b = dynamic_cast<gdcm::BinEntry*>(d) )
          {
+            uint8_t* copybin = new uint8_t[b->GetLength()];
+           if (b->GetBinArea())
+               memcpy(copybin,b->GetBinArea(), b->GetLength());
+           else
+              copybin = 0;
             copy->GetHeader()->ReplaceOrCreateByNumber(
-                                 b->GetBinArea(),
+                                 copybin,
                                  b->GetLength(),
                                  b->GetGroup(),
                                  b->GetElement(),
@@ -130,7 +136,6 @@
          }
       }

-      copy->SetImageData(imageData, dataSize);
       original->GetHeader()->SetImageDataSize(dataSize);

       copy->WriteDcmExplVR( output );
@@ -147,6 +152,7 @@
          std::cout << output << " Failed" << std::endl;
       }
       i++;
+      delete copy;
    }
    return retVal;
 }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.creatis.insa-lyon.fr/pipermail/dcmlib/attachments/20041116/d37da3e2/attachment.html>


More information about the Dcmlib mailing list