From 1d2e9cb443091787490246f58833a658cebc5701 Mon Sep 17 00:00:00 2001 From: eap Date: Wed, 19 Jun 2013 14:23:50 +0000 Subject: [PATCH] 0022232: [CEA 837] Memory corruption in GEOM/SMESH that leads to segfault on debian64 Fix "Mismatched free() / delete / delete []" valgrind error - Standard_EXPORT char* GetName(); + Standard_EXPORT TCollection_AsciiString GetName(); --- src/GEOM/GEOM_Object.cxx | 10 +++++----- src/GEOM/GEOM_Object.hxx | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/GEOM/GEOM_Object.cxx b/src/GEOM/GEOM_Object.cxx index 1d42b7602..0c488e56b 100644 --- a/src/GEOM/GEOM_Object.cxx +++ b/src/GEOM/GEOM_Object.cxx @@ -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; } //============================================================================= diff --git a/src/GEOM/GEOM_Object.hxx b/src/GEOM/GEOM_Object.hxx index cc1160d2f..3a9cf7460 100644 --- a/src/GEOM/GEOM_Object.hxx +++ b/src/GEOM/GEOM_Object.hxx @@ -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); -- 2.30.2