]> Creatis software - gdcm.git/commitdiff
* Remove memory leaks
authorregrain <regrain>
Wed, 19 Oct 2005 13:15:36 +0000 (13:15 +0000)
committerregrain <regrain>
Wed, 19 Oct 2005 13:15:36 +0000 (13:15 +0000)
   -- BeNours

Testing/TestBuildUpDicomDir.cxx
Testing/TestReadWriteReadCompare.cxx
src/gdcmDicomDir.cxx
src/gdcmDocument.cxx

index da7c881f31044cb562dbba01092e4ea4d7d6b080..1aa9cb6fcf95cc0873c0a785bd55a13bf68e8d97 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: TestBuildUpDicomDir.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/18 08:35:46 $
-  Version:   $Revision: 1.5 $
+  Date:      $Date: 2005/10/19 13:15:36 $
+  Version:   $Revision: 1.6 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -37,7 +37,7 @@ int TestBuildUpDicomDir(int argc, char *argv[])
 {
    if (argc) 
    {
-      std::cerr << "Usage: " << argv[0] << " dummy ";
+      std::cerr << "Usage: " << argv[0] << " dummy " << std::endl;
    }
 
    gdcm::DicomDir *dcmdir;
@@ -182,6 +182,7 @@ int TestBuildUpDicomDir(int argc, char *argv[])
 
    // Write it on disc
    dcmdir->Write("NewDICOMDIR");
+
    delete dcmdir;
 
    // Read the newly written DicomDir
@@ -345,27 +346,15 @@ int TestBuildUpDicomDir(int argc, char *argv[])
          errorFound = true;
          break;
       } 
-/*
-      if ( s1111->GetEntryString(0x0004,0x1500) != "imageFileName1111 " )
-      {
-         errorFound = true;
-         break;
-      }
-*/
+
       if ( (s1112 = s111->GetNextImage()) == 0 )
       {
          std::cout << "missing image S1112" << std::endl;
          errorFound = true;
          break;
       }
-/*
-      if ( s1112->GetEntryString(0x0004,0x1500) != "imageFileName1112 " )
-      {
-         errorFound = true;
-         break;
-      }
-  */
-     break; // No error found. Stop looping
+
+      break; // No error found. Stop looping
    }
 
    delete newDicomDir;
index f6a2a7eb272ebf17e97cdbd18de5cfc2054edd9d..2fe46dee09ae2c02199e417fac110c0f83f1e645 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: TestReadWriteReadCompare.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/18 08:35:46 $
-  Version:   $Revision: 1.25 $
+  Date:      $Date: 2005/10/19 13:15:37 $
+  Version:   $Revision: 1.26 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -63,12 +63,13 @@ int CompareInternal(std::string const &filename, std::string const &output)
 
    if( !fileout->IsReadable() )
    {
-     std::cout << "Failed" << std::endl
-               << "Test::TestReadWriteReadCompare: Could not parse the newly "
-               << "written image:" << filename << std::endl;
-     delete file;
-     delete filehelper;
-     return 1;
+      std::cout << "Failed" << std::endl
+                << "Test::TestReadWriteReadCompare: Could not parse the newly "
+                << "written image:" << filename << std::endl;
+      delete file;
+      delete filehelper;
+      delete fileout;
+      return 1;
    }
 
    gdcm::FileHelper *reread = new gdcm::FileHelper( fileout );
@@ -94,6 +95,7 @@ int CompareInternal(std::string const &filename, std::string const &output)
                   << reread->GetFile()->GetZSize() << std::endl;
       delete file;
       delete filehelper;
+      delete fileout;
       delete reread;
       return 1;
    }
@@ -106,6 +108,7 @@ int CompareInternal(std::string const &filename, std::string const &output)
          << dataSize << " # " << dataSizeWritten << std::endl;
       delete file;
       delete filehelper;
+      delete fileout;
       delete reread;
       return 1;
    }
@@ -117,6 +120,7 @@ int CompareInternal(std::string const &filename, std::string const &output)
          << "        Pixel differ (as expanded in memory)." << std::endl;
       delete file;
       delete filehelper;
+      delete fileout;
       delete reread;
       return 1;
    }
@@ -125,6 +129,7 @@ int CompareInternal(std::string const &filename, std::string const &output)
    //////////////// Clean up:
    delete file;
    delete filehelper;
+   delete fileout;
    delete reread;
 
    return 0;
index 67195605e1710b55bd2605fbe2c6191e3fe8568b..fd8158c7dff8a4d34f9a959541536e842316752f 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDir.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/18 08:35:49 $
-  Version:   $Revision: 1.160 $
+  Date:      $Date: 2005/10/19 13:15:38 $
+  Version:   $Revision: 1.161 $
   
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -181,9 +181,6 @@ DicomDir::~DicomDir()
  */
 bool DicomDir::Load( ) 
 {
-   // We should clean out anything that already exists.
-   Initialize();  // sets all private fields to NULL
-
    if (!ParseDir)
    {
       if ( ! this->Document::Load( ) )
@@ -204,14 +201,7 @@ bool DicomDir::Load(std::string const &fileName )
 {
    // We should clean out anything that already exists.
    Initialize();  // sets all private fields to NULL
-
-   SetFileName( fileName );
-   if (!ParseDir)
-   {
-      if ( ! this->Document::Load( ) )
-         return false;
-   }
-   return DoTheLoadingJob( );
+   return Load();
 }
 
 /// DEPRECATED : use SetDirectoryName(dname) instead
@@ -233,18 +223,14 @@ void DicomDir::SetParseDir(bool parseDir)
  */
 bool DicomDir::DoTheLoadingJob( ) 
 {
-   // We should clean out anything that already exists.
-   Initialize();  // sets all private fields to NULL
+   Progress = 0.0f;
+   Abort = false;
 
    if (!ParseDir)
    {
    // Only if user passed a DICOMDIR
    // ------------------------------
       Fp = 0;
-      if ( !OpenFile() )
-      {
-         return false;
-      }
       if (!Document::Load() )
       {
          return false;
@@ -855,8 +841,6 @@ void DicomDir::CreateDicomDir()
         continue;
       }
       if ( si )
-         //MoveSQItem(si,tmpSI); // Old code : Copies each Entry
-                                 //  -and then removes the source-
          si->MoveObject(tmpSI);  // New code : Copies the List
 
       tmpSI=s->GetNextSQItem();
@@ -1080,14 +1064,14 @@ void DicomDir::SetElement(std::string const &path, DicomDirType type,
          }
          break;
       case GDCM_DICOMDIR_META:
-         elemList = Global::GetDicomDirElements()->GetDicomDirMetaElements();
-         si = new DicomDirMeta(true);
          if ( MetaElems )
          {
             delete MetaElems;
             gdcmErrorMacro( "MetaElements already exist, they will be destroyed");
          }
-         MetaElems = static_cast<DicomDirMeta *>(si);
+         elemList = Global::GetDicomDirElements()->GetDicomDirMetaElements();
+         MetaElems = new DicomDirMeta(true);
+         si = MetaElems;
          break;
       default:
          return;
index 15680d25ca17513ffd993479745ef1f7e7ef9972..4e9f21f5d403fbb824a333826e2d896de5730239 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/19 12:01:50 $
-  Version:   $Revision: 1.298 $
+  Date:      $Date: 2005/10/19 13:15:39 $
+  Version:   $Revision: 1.299 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -1081,8 +1081,7 @@ void Document::ParseDES(DocEntrySet *set, long offset,
             if ( newDocEntry->GetGroup()%2 != 0 )
             {
                 Fp->seekg( l, std::ios::cur);
-                RemoveEntry( newDocEntry );  // Remove and delete
-                //used = false; // never used
+                delete newDocEntry;  // Delete, not in the set 
                 continue;  
             } 
          } 
@@ -1090,8 +1089,7 @@ void Document::ParseDES(DocEntrySet *set, long offset,
          {
            // User asked to skip *any* SeQuence
             Fp->seekg( l, std::ios::cur);
-            //used = false; // never used
-            RemoveEntry( newDocEntry );  // Remove and delete
+            delete newDocEntry; // Delete, not in the set
             continue;
          }
          // delay the dynamic cast as late as possible
@@ -1104,11 +1102,9 @@ void Document::ParseDES(DocEntrySet *set, long offset,
          // is a Document, then we are building the first depth level.
          // Hence the SeqEntry we are building simply has a depth
          // level of one:
-//         SQItem *parentSQItem = dynamic_cast< SQItem* > ( set );
         if ( set == this ) // ( dynamic_cast< Document* > ( set ) )
          {
             newSeqEntry->SetDepthLevel( 1 );
-         //   newSeqEntry->SetKey( newSeqEntry->GetKey() );
          }
          // But when "set" is already a SQItem, we are building a nested
          // sequence, and hence the depth level of the new SeqEntry
@@ -1118,9 +1114,6 @@ void Document::ParseDES(DocEntrySet *set, long offset,
          else if (SQItem *parentSQItem = dynamic_cast< SQItem* > ( set ) )
          {
             newSeqEntry->SetDepthLevel( parentSQItem->GetDepthLevel() + 1 );
-
-          //  newSeqEntry->SetKey(  parentSQItem->GetBaseTagKey()
-          //                      + newSeqEntry->GetKey() );
          }
 
          if ( l != 0 )