]> Creatis software - gdcm.git/commitdiff
* Memory leak hunt with the following command:
authorfrog <frog>
Mon, 14 Jun 2004 08:35:35 +0000 (08:35 +0000)
committerfrog <frog>
Mon, 14 Jun 2004 08:35:35 +0000 (08:35 +0000)
      valgrind --leak-check=yes --leak-resolution=high --num-callers=40
               --show-reachable=yes gdcmTests PrintDocument
      It looks like many (all?) leaks are due to the STL (or a bad usage
      of the STL. The lines producing the leaks now have a comment with
      a "MEMORY LEAK" tag: you can retrieve them with
          grep "MEMORY LEAK" src/*
      Here are two typical examples which I can't help fixing:
      -----
          #include <string>
          int main() {
             std::string name;
             char * test = "babo";
             name = test;    //// <--- valgrind detects 960 bytes lost in
                             ////   call to std::string::operator=(char const*)
             name.clear();   //// Doesn't help !
             return 0;
          }
      -----
          #include <string>
          #include <iostream>
          int main() {
             std::string line;
             std::cout << "Type a bunch of characters followed by RETURN: ";
             getline(std::cin, line);   //// <--- valgrind dectects a loss
                                        //// of 1320 bytes in call to
                                        /// std::basic_istream<>& std::getline<>
             return 0;
          }
      -----

ChangeLog
gdcmPython/gdcm.i
src/gdcmCommon.h
src/gdcmDict.cxx
src/gdcmDictSet.cxx
src/gdcmSeqEntry.h
src/gdcmTS.cxx

index 37ca0b884335ecbcd0ce874e1e787c88cc88fefd..4e508b884a06c2e07fec1b1966c650844a30efdf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,36 @@
+2004-06-14 Eric Boix <Eric.Boix@creatis.insa-lyon.fr>
+    * Memory leak hunt with the following command:
+      valgrind --leak-check=yes --leak-resolution=high --num-callers=40
+               --show-reachable=yes gdcmTests PrintDocument
+      It looks like many (all?) leaks are due to the STL (or a bad usage
+      of the STL. The lines producing the leaks now have a comment with
+      a "MEMORY LEAK" tag: you can retrieve them with 
+          grep "MEMORY LEAK" src/*
+      Here are two typical examples which I can't help fixing:
+      -----
+          #include <string>
+          int main() {
+             std::string name;
+             char * test = "babo";
+             name = test;    //// <--- valgrind detects 960 bytes lost in
+                             ////   call to std::string::operator=(char const*)
+             name.clear();   //// Doesn't help !
+             return 0;
+          }
+      -----
+          #include <string>
+          #include <iostream>
+          int main() {
+             std::string line;
+             std::cout << "Type a bunch of characters followed by RETURN: ";
+             getline(std::cin, line);   //// <--- valgrind dectects a loss
+                                        //// of 1320 bytes in call to
+                                        /// std::basic_istream<>& std::getline<>
+            return 0;
+          }
+      -----
+
+
 2004-06-10 Eric Boix <Eric.Boix@creatis.insa-lyon.fr>
     * src/gdcmHeader.[cxx|h]:
       - Predicates on the Transfer syntax (of the form Is[JPEF|RLE]*)
index 9929125a975201a4732e5ede1a4f96757b3fb8ad..40b0ef9bb9ae4ea456b1561866454e260ca3c489 100644 (file)
@@ -72,62 +72,68 @@ typedef  unsigned int guint32;
 
 ////////////////////////////////////////////////////////////////////////////
 %typemap(out) std::list<std::string> * {
-       PyObject* NewItem = (PyObject*)0;
-       PyObject* NewList = PyList_New(0); // The result of this typemap
-       for (std::list<std::string>::iterator NewString = ($1)->begin();
-            NewString != ($1)->end(); ++NewString) {
-               NewItem = PyString_FromString(NewString->c_str());
-               PyList_Append( NewList, NewItem);
-       }
-       $result = NewList;
+   PyObject* NewItem = (PyObject*)0;
+   PyObject* NewList = PyList_New(0); // The result of this typemap
+
+   for (std::list<std::string>::iterator NewString = ($1)->begin();
+        NewString != ($1)->end();
+        ++NewString)
+   {
+      NewItem = PyString_FromString(NewString->c_str());
+      PyList_Append( NewList, NewItem);
+   }
+   $result = NewList;
 }
 
 ////////////////////////////////////////////////////////////////////////////
 // Convert a c++ hash table in a python native dictionary
 %typemap(out) std::map<std::string, std::list<std::string> > * {
-       PyObject* NewDict = PyDict_New(); // The result of this typemap
-       PyObject* NewKey = (PyObject*)0;
-       PyObject* NewVal = (PyObject*)0;
-
-       for (std::map<std::string, std::list<std::string> >::iterator tag = ($1)->begin();
-            tag != ($1)->end(); ++tag) {
+   PyObject* NewDict = PyDict_New(); // The result of this typemap
+   PyObject* NewKey = (PyObject*)0;
+   PyObject* NewVal = (PyObject*)0;
+
+   for (std::map<std::string,
+        std::list<std::string> >::iterator tag = ($1)->begin();
+        tag != ($1)->end(); ++tag)
+   {
       std::string first = tag->first;
       // Do not publish entries whose keys is made of spaces
       if (first.length() == 0)
          continue;
-               NewKey = PyString_FromString(first.c_str());
-               PyObject* NewList = PyList_New(0);
-               for (std::list<std::string>::iterator Item = tag->second.begin();
-                    Item != tag->second.end(); ++Item) {
-                       NewVal = PyString_FromString(Item->c_str());
-                       PyList_Append( NewList, NewVal);
-               }
-               PyDict_SetItem( NewDict, NewKey, NewList);
-       }
-       $result = NewDict;
+      NewKey = PyString_FromString(first.c_str());
+      PyObject* NewList = PyList_New(0);
+      for (std::list<std::string>::iterator Item = tag->second.begin();
+           Item != tag->second.end();
+           ++Item)
+      {
+         NewVal = PyString_FromString(Item->c_str());
+         PyList_Append( NewList, NewVal);
+      }
+      PyDict_SetItem( NewDict, NewKey, NewList);
+   }
+   $result = NewDict;
 }
 
 ////////////////////////////////////////////////////////////////////////////
 // Convert a c++ hash table in a python native dictionary
 %typemap(out) TagDocEntryHT & {
-       PyObject* NewDict = PyDict_New(); // The result of this typemap
-       std::string RawName;                   // Element name as gotten from gdcm
-       PyObject* NewKey = (PyObject*)0;  // Associated name as python object
-       std::string RawValue;                  // Element value as gotten from gdcm
-       PyObject* NewVal = (PyObject*)0;  // Associated value as python object
-
-       for (TagDocEntryHT::iterator tag = $1->begin(); tag != $1->end(); ++tag) {
+   PyObject* NewDict = PyDict_New(); // The result of this typemap
+   std::string RawName;              // Element name as gotten from gdcm
+   PyObject* NewKey = (PyObject*)0;  // Associated name as python object
+   std::string RawValue;             // Element value as gotten from gdcm
+   PyObject* NewVal = (PyObject*)0;  // Associated value as python object
+
+   for (TagDocEntryHT::iterator tag = $1->begin(); tag != $1->end(); ++tag)
+   {
+      // The element name shall be the key:
+      RawName = tag->second->GetName();
+      // gdcm unrecognized (including not loaded because their size exceeds
+      // the user specified treshold) elements are exported with their
+      // TagKey as key.
+      if (RawName == "Unknown")
+         RawName = tag->second->GetKey();
+      NewKey = PyString_FromString(RawName.c_str());
 
-               // The element name shall be the key:
-               RawName = tag->second->GetName();
-               // gdcm unrecognized (including not loaded because their size exceeds
-               // the user specified treshold) elements are exported with their
-               // TagKey as key.
-               if (RawName == "Unknown")
-                       RawName = tag->second->GetKey();
-               NewKey = PyString_FromString(RawName.c_str());
-
-      // Element values are striped from leading/trailing spaces
       // Element values are striped from leading/trailing spaces
       if (gdcmValEntry* ValEntryPtr =
                 dynamic_cast< gdcmValEntry* >(tag->second) )
@@ -138,49 +144,11 @@ typedef  unsigned int guint32;
         continue; 
       EatLeadingAndTrailingSpaces(RawValue);
       NewVal = PyString_FromString(RawValue.c_str());
-
       PyDict_SetItem( NewDict, NewKey, NewVal);
    }
    $result = NewDict;
 }
 
-/*
-CLEAN ME FIXME CLEANME TODO
-%typemap(out) TagDocEntryHT {
-       PyObject* NewDict = PyDict_New(); // The result of this typemap
-       std::string RawName;              // Element name as gotten from gdcm
-       PyObject* NewKey = (PyObject*)0;  // Associated name as python object
-       std::string RawValue;             // Element value as gotten from gdcm
-       PyObject* NewVal = (PyObject*)0;  // Associated value as python object
-
-       for (TagDocEntryHT::iterator tag = $1.begin(); tag != $1.end(); ++tag) {
-
-               // The element name shall be the key:
-               RawName = tag->second->GetName();
-               // gdcm unrecognized (including not loaded because their size exceeds
-               // the user specified treshold) elements are exported with their
-               // TagKey as key.
-               if (RawName == "Unknown")
-                       RawName = tag->second->GetKey();
-               NewKey = PyString_FromString(RawName.c_str());
-
-      // Element values are striped from leading/trailing spaces
-      if (gdcmValEntry* ValEntryPtr =
-                dynamic_cast< gdcmValEntry* >(tag->second) )
-      {
-         RawValue = ValEntryPtr->GetValue();
-      } 
-      else
-        continue;
-               EatLeadingAndTrailingSpaces(RawValue);
-               NewVal = PyString_FromString(RawValue.c_str());
-
-               PyDict_SetItem( NewDict, NewKey, NewVal);
-    }
-       $result = NewDict;
-}
-*/
-
 ////////////////////////////////////////////////////////////////////////////
 %typemap(out) ListDicomDirPatient & {
        PyObject* NewItem = (PyObject*)0;
index 4f9d4ece6adbef1bb35868e646747e3c20ef1517..46c3bc299485b32d956af6106e48f7f4da6ab8e0 100644 (file)
@@ -81,7 +81,7 @@ typedef  int            gint32;
 
 #include <string>
 
-const std::string GDCM_UNFOUND = "gdcm::Unfound";
+const std::string GDCM_UNFOUND = "gdcm::Unfound";   /// MEMORY LEAK
 
 typedef std::string TagKey;
 typedef std::string TagName;
index 7d9585cdc1ff65d78682e514fc8b91a5c5077eac..46edb403e836229cf88e29f171d4c5e9b11ff5db 100644 (file)
@@ -26,15 +26,12 @@ gdcmDict::gdcmDict(std::string & FileName) {
                     FileName.c_str());
 
    while (!from.eof()) {
-      from >> std::hex >> group >> element;
-      eatwhite(from);
-      from.getline(buff, 256, ' ');
-      vr = buff;
-      eatwhite(from);
-      from.getline(buff, 256, ' ');
-      fourth = buff;
-      from.getline(buff, 256, '\n');
-      name = buff;
+      from >> std::hex;
+      from >> group;          /// MEMORY LEAK in std::istream::operator>>
+      from >> element;
+      from >> vr;
+      from >> fourth;
+      getline(from, name);    /// MEMORY LEAK in std::getline<>
 
       gdcmDictEntry * newEntry = new gdcmDictEntry(group, element,
                                                    vr, fourth, name);
@@ -135,7 +132,8 @@ bool gdcmDict::AddNewEntry(gdcmDictEntry *NewEntry)
    else 
    {
       KeyHt[NewEntry->GetKey()] = NewEntry;
-      NameHt[NewEntry->GetName()] = NewEntry;
+      NameHt[NewEntry->GetName()] = NewEntry;  /// MEMORY LEAK in
+                                               /// std::map<>::operator[]
       return(true);
    }
 }
index 0a407bb4657f54311efd467b63a3f0e6660a7ead..882344aeef27d64adc399083d7e3b3b4f851b66f 100644 (file)
@@ -15,7 +15,8 @@
 gdcmDictSet::gdcmDictSet(void) 
 {
    DictPath = BuildDictPath();
-   std::string PubDictFile = DictPath + PUB_DICT_FILENAME;
+   std::string PubDictFile(DictPath);
+   PubDictFile += PUB_DICT_FILENAME;  /// MEMORY LEAK std::string::operator+=
    Dicts[PUB_DICT_NAME] = new gdcmDict(PubDictFile);
 }
 
index e197bc04db672432b80785aadf207b5e6fb0a0d6..143e382b13697223af891745e0b0e805979dc130 100644 (file)
@@ -20,22 +20,19 @@ public:
    
    virtual void Print(std::ostream &os = std::cout); 
 
- /// \brief   returns the SQITEM chained List for this SeQuence.
-   inline ListSQItem &GetSQItems() 
-      {return items;};
+   /// \brief   returns the SQITEM chained List for this SeQuence.
+   inline ListSQItem &GetSQItems() {return items;};
       
- /// \brief Sets the delimitor mode
-    inline void SetDelimitorMode(bool dm) 
-       { delimitor_mode = dm;}
+   /// \brief Sets the delimitor mode
+   inline void SetDelimitorMode(bool dm) { delimitor_mode = dm;}
 
- /// \brief Sets the Sequence Delimitation Item
-    inline void SetSequenceDelimitationItem(gdcmDocEntry * e) 
-       { seq_term = e;}
+   /// \brief Sets the Sequence Delimitation Item
+   inline void SetSequenceDelimitationItem(gdcmDocEntry * e) { seq_term = e;}
        
-    void AddEntry(gdcmSQItem *it); 
+   void AddEntry(gdcmSQItem *it); 
 
/// \brief   creates a new SQITEM for this SeQuence.
-    gdcmSQItem * NewItem(void);
  /// \brief creates a new SQITEM for this SeQuence.
+   gdcmSQItem * NewItem(void);
     
    gdcmDocEntry *NewDocEntryByNumber(guint16 group, guint16 element);    
    gdcmDocEntry *NewDocEntryByName  (std::string Name); 
@@ -46,21 +43,18 @@ public:
 protected:
 
 private:
-
 // Variables
 
-/// \brief If this Sequence is in delimitor mode (length =0xffffffff) or not
+   /// \brief If this Sequence is in delimitor mode (length =0xffffffff) or not
    bool delimitor_mode;
    
-/// \brief chained list of SQ Items
+   /// \brief Chained list of SQ Items
    ListSQItem items;
    
-/// \brief sequence terminator item 
+   /// \brief sequence terminator item 
    gdcmDocEntry *seq_term;
-
 };
 
-
 //-----------------------------------------------------------------------------
 #endif
 
index 0712d1db9705799b46dfdb7d8e15d63227a8f64d..e6543d8cd4a6f9c49e778380de2a58d356983760 100644 (file)
@@ -24,13 +24,8 @@ gdcmTS::gdcmTS(void)
    std::string name;
 
    while (!from.eof()) {
-      eatwhite(from);
-      from.getline(buff, 1024, ' ');
-      key = buff;
-
-      eatwhite(from);
-      from.getline(buff, 1024, '\n');
-      name = buff;
+      from >> key;
+      getline(from, name);    /// MEMORY LEAK
 
       if(key!="") 
       {