From 2ce6422178e709073fc24aa2e3d4f5069711cd18 Mon Sep 17 00:00:00 2001 From: regrain Date: Wed, 19 Oct 2005 13:15:36 +0000 Subject: [PATCH] * Remove memory leaks -- BeNours --- Testing/TestBuildUpDicomDir.cxx | 25 ++++++---------------- Testing/TestReadWriteReadCompare.cxx | 21 +++++++++++------- src/gdcmDicomDir.cxx | 32 +++++++--------------------- src/gdcmDocument.cxx | 15 ++++--------- 4 files changed, 32 insertions(+), 61 deletions(-) diff --git a/Testing/TestBuildUpDicomDir.cxx b/Testing/TestBuildUpDicomDir.cxx index da7c881f..1aa9cb6f 100644 --- a/Testing/TestBuildUpDicomDir.cxx +++ b/Testing/TestBuildUpDicomDir.cxx @@ -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; diff --git a/Testing/TestReadWriteReadCompare.cxx b/Testing/TestReadWriteReadCompare.cxx index f6a2a7eb..2fe46dee 100644 --- a/Testing/TestReadWriteReadCompare.cxx +++ b/Testing/TestReadWriteReadCompare.cxx @@ -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; diff --git a/src/gdcmDicomDir.cxx b/src/gdcmDicomDir.cxx index 67195605..fd8158c7 100644 --- a/src/gdcmDicomDir.cxx +++ b/src/gdcmDicomDir.cxx @@ -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(si); + elemList = Global::GetDicomDirElements()->GetDicomDirMetaElements(); + MetaElems = new DicomDirMeta(true); + si = MetaElems; break; default: return; diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index 15680d25..4e9f21f5 100644 --- a/src/gdcmDocument.cxx +++ b/src/gdcmDocument.cxx @@ -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 ) -- 2.45.1