From: regrain Date: Mon, 15 Nov 2004 16:12:30 +0000 (+0000) Subject: * src/gdcmDocument.[cxx|h] : fix memory leaks. The return is suppressed X-Git-Tag: Version1.0.bp~605 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=eb427dc05df82e0d814ea43533e7711ba35d189a;p=gdcm.git * src/gdcmDocument.[cxx|h] : fix memory leaks. The return is suppressed because never used... and in the same time, that's remove some memory leaks -- BeNours --- diff --git a/ChangeLog b/ChangeLog index ed477178..00f994e4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2004-11-15 Benoit Regrain + * src/gdcmDocument.[cxx|h] : fix memory leaks. The return is suppressed + because never used... and in the same time, that's remove some memory leaks + 2004-11-15 Benoit Regrain * src/gdcmFile.cxx : now delete the PixelConvert instance. * In examples and tests : change the type of image data variables from void* diff --git a/src/gdcmBinEntry.cxx b/src/gdcmBinEntry.cxx index f6645e7b..22dbae3c 100644 --- a/src/gdcmBinEntry.cxx +++ b/src/gdcmBinEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmBinEntry.cxx,v $ Language: C++ - Date: $Date: 2004/11/03 20:52:12 $ - Version: $Revision: 1.35 $ + Date: $Date: 2004/11/15 16:12:30 $ + Version: $Revision: 1.36 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -129,7 +129,7 @@ void BinEntry::SetBinArea( uint8_t* area ) { if (BinArea) delete[] BinArea; - BinArea = area; + BinArea = area; } //----------------------------------------------------------------------------- diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index e406a1c4..879a3348 100644 --- a/src/gdcmDocument.cxx +++ b/src/gdcmDocument.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocument.cxx,v $ Language: C++ - Date: $Date: 2004/11/12 21:33:46 $ - Version: $Revision: 1.122 $ + Date: $Date: 2004/11/15 16:12:30 $ + Version: $Revision: 1.123 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -1044,13 +1044,13 @@ void* Document::GetEntryBinAreaByNumber(uint16_t group, uint16_t elem) * @param group group number of the Entry * @param elem element number of the Entry */ -void* Document::LoadEntryBinArea(uint16_t group, uint16_t elem) +void Document::LoadEntryBinArea(uint16_t group, uint16_t elem) { + // Search the corresponding DocEntry DocEntry *docElement = GetDocEntryByNumber(group, elem); if ( !docElement ) - { - return NULL; - } + return; + size_t o =(size_t)docElement->GetOffset(); Fp->seekg( o, std::ios_base::beg); size_t l = docElement->GetLength(); @@ -1058,27 +1058,30 @@ void* Document::LoadEntryBinArea(uint16_t group, uint16_t elem) if(!a) { dbg.Verbose(0, "Document::LoadEntryBinArea cannot allocate a"); - return NULL; + return; } + + // Read the value Fp->read((char*)a, l); if( Fp->fail() || Fp->eof() )//Fp->gcount() == 1 { delete[] a; - return NULL; + return; } - /// \todo Drop any already existing void area! JPR + + // Set the value to the DocEntry if( !SetEntryBinAreaByNumber( a, group, elem ) ) { + delete[] a; dbg.Verbose(0, "Document::LoadEntryBinArea setting failed."); } - return a; } /** * \brief Loads (from disk) the element content * when a string is not suitable * @param element Entry whose binArea is going to be loaded */ -void* Document::LoadEntryBinArea(BinEntry* element) +void Document::LoadEntryBinArea(BinEntry* element) { size_t o =(size_t)element->GetOffset(); Fp->seekg(o, std::ios_base::beg); @@ -1087,18 +1090,18 @@ void* Document::LoadEntryBinArea(BinEntry* element) if( !a ) { dbg.Verbose(0, "Document::LoadEntryBinArea cannot allocate a"); - return NULL; + return; } - element->SetBinArea((uint8_t*)a); + /// \todo check the result Fp->read((char*)a, l); if( Fp->fail() || Fp->eof()) //Fp->gcount() == 1 { delete[] a; - return NULL; + return; } - return a; + element->SetBinArea((uint8_t*)a); } /** @@ -1116,12 +1119,14 @@ bool Document::SetEntryBinAreaByNumber(uint8_t* area, { return false; } + if ( BinEntry* binEntry = dynamic_cast(currentEntry) ) { binEntry->SetBinArea( area ); return true; } - return true; + + return false; } /** diff --git a/src/gdcmDocument.h b/src/gdcmDocument.h index 0324a946..26cca8c8 100644 --- a/src/gdcmDocument.h +++ b/src/gdcmDocument.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocument.h,v $ Language: C++ - Date: $Date: 2004/11/12 21:33:46 $ - Version: $Revision: 1.57 $ + Date: $Date: 2004/11/15 16:12:30 $ + Version: $Revision: 1.58 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -164,8 +164,8 @@ public: bool ReplaceIfExistByNumber ( std::string const & value, uint16_t group, uint16_t elem ); - virtual void* LoadEntryBinArea(uint16_t group, uint16_t elem); - virtual void* LoadEntryBinArea(BinEntry* entry); + virtual void LoadEntryBinArea(uint16_t group, uint16_t elem); + virtual void LoadEntryBinArea(BinEntry* entry); // System access (meaning endian related !?) uint16_t SwapShort(uint16_t); // needed by File