Salome HOME
0022232: [CEA 837] Memory corruption in GEOM/SMESH that leads to segfault on debian64
authoreap <eap@opencascade.com>
Wed, 19 Jun 2013 14:23:50 +0000 (14:23 +0000)
committereap <eap@opencascade.com>
Wed, 19 Jun 2013 14:23:50 +0000 (14:23 +0000)
Fix "Mismatched free() / delete / delete []" valgrind error

-  Standard_EXPORT char* GetName();
+  Standard_EXPORT TCollection_AsciiString GetName();

src/GEOM/GEOM_Object.cxx
src/GEOM/GEOM_Object.hxx

index 1d42b76025dc9c82d474f768423d1e60d166c1e6..0c488e56b713123fc6bc567988d0935f8609c30b 100644 (file)
@@ -314,16 +314,16 @@ void GEOM_Object::SetName(const char* theName)
  *  GetName
  */
 //=============================================================================
-char* GEOM_Object::GetName()
+TCollection_AsciiString GEOM_Object::GetName()
 {
+  TCollection_AsciiString aName;
   Handle(TDataStd_Name) aNameAttr;
-  if(!_label.FindAttribute(TDataStd_Name::GetID(), aNameAttr)) return NULL;
-
-  TCollection_AsciiString aName(aNameAttr->Get());
+  if(_label.FindAttribute(TDataStd_Name::GetID(), aNameAttr))
+    aName = aNameAttr->Get();
   // do not return pointer of local variable
   // return aName.ToCString();
   // the following code could lead to memory leak, so take care about recieved pointer
-  return strdup(aName.ToCString());
+  return aName;
 }
 
 //=============================================================================
index cc1160d2f3a0a32124bd1cc34d3ba58b05124b49..3a9cf74600b78e4daf2b70d6079785007f6ec5b1 100644 (file)
@@ -213,7 +213,7 @@ class GEOM_Object : public MMgt_TShared
   Standard_EXPORT void SetName(const char* theName);
 
   //Returns a name of this GEOM_Object
-  Standard_EXPORT char* GetName();
+  Standard_EXPORT TCollection_AsciiString GetName();
 
   //Sets a color of this GEOM_Object
   Standard_EXPORT void SetColor(const Color& theColor);