From: ptv Date: Fri, 14 Jul 2006 05:29:13 +0000 (+0000) Subject: remove memory leaks uninitalised memory read, etc... X-Git-Tag: LAST_STABLE_VERSION_21_09_2006_ON_3_2_0~11 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1cc9d0bb1a87bd32632a3719417f4a7aa5859eca;p=modules%2Fgeom.git remove memory leaks uninitalised memory read, etc... noticed with Rational Purify on Windows --- diff --git a/src/GEOM/GEOM_Object.cxx b/src/GEOM/GEOM_Object.cxx index e36ddc909..2ce73e4ef 100644 --- a/src/GEOM/GEOM_Object.cxx +++ b/src/GEOM/GEOM_Object.cxx @@ -220,8 +220,12 @@ char* GEOM_Object::GetName() Handle(TDataStd_Name) aNameAttr; if(!_label.FindAttribute(TDataStd_Name::GetID(), aNameAttr)) return NULL; + // do not TCollection_AsciiString aName(aNameAttr->Get()); - return aName.ToCString(); + // 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()); } //============================================================================= diff --git a/src/GEOMBase/GEOMBase.cxx b/src/GEOMBase/GEOMBase.cxx index a716f062a..3423c9c17 100644 --- a/src/GEOMBase/GEOMBase.cxx +++ b/src/GEOMBase/GEOMBase.cxx @@ -940,10 +940,10 @@ QString GEOMBase::GetName( GEOM::GEOM_Object_ptr theObj ) if ( appStudy ) { - string anIOR = SalomeApp_Application::orb()->object_to_string( theObj ); - if ( anIOR != "" ) + CORBA::String_var anIOR = SalomeApp_Application::orb()->object_to_string( theObj ); + if ( strcmp(anIOR.in(), "") != 0 ) { - _PTR(SObject) aSObj ( appStudy->studyDS()->FindObjectIOR( anIOR ) ); + _PTR(SObject) aSObj ( appStudy->studyDS()->FindObjectIOR( string( anIOR ) ) ); _PTR(GenericAttribute) anAttr; diff --git a/src/GEOMBase/GEOMBase_Helper.cxx b/src/GEOMBase/GEOMBase_Helper.cxx index 9cd2a40d6..fe51c488f 100755 --- a/src/GEOMBase/GEOMBase_Helper.cxx +++ b/src/GEOMBase/GEOMBase_Helper.cxx @@ -215,7 +215,8 @@ void GEOMBase_Helper::redisplay( GEOM::GEOM_Object_ptr object, SalomeApp_Study* aDoc = getStudy(); if ( aDoc && aDoc->studyDS() ) { _PTR(Study) aStudy = aDoc->studyDS(); - _PTR(SObject) aSObj (aStudy->FindObjectIOR(SalomeApp_Application::orb()->object_to_string(object))); + CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string(object); + _PTR(SObject) aSObj (aStudy->FindObjectIOR(string(objStr.in()))); if ( aSObj ) { _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) ); for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) { @@ -302,7 +303,8 @@ void GEOMBase_Helper::displayPreview( GEOM::GEOM_Object_ptr object, getDisplayer()->SetToActivate( activate ); // Make a reference to GEOM_Object - getDisplayer()->SetName( SalomeApp_Application::orb()->object_to_string( object ) ); + CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string( object ); + getDisplayer()->SetName( objStr.in() ); // Build prs SALOME_Prs* aPrs = getDisplayer()->BuildPrs( object ); @@ -571,11 +573,13 @@ char* GEOMBase_Helper::getEntry( GEOM::GEOM_Object_ptr object ) const { SalomeApp_Study* study = getStudy(); if ( study ) { - string IOR = GEOMBase::GetIORFromObject( object); + char * objIOR = GEOMBase::GetIORFromObject( object ); + string IOR( objIOR ); + free( objIOR ); if ( IOR != "" ) { _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) ); if ( SO ) { - return TCollection_AsciiString((char*)SO->GetID().c_str()).ToCString(); + return TCollection_AsciiString((char*)SO->GetID().c_str()).ToCString(); } } } @@ -602,15 +606,15 @@ void GEOMBase_Helper::clearShapeBuffer( GEOM::GEOM_Object_ptr theObj ) if ( CORBA::is_nil( theObj ) ) return; - string IOR = SalomeApp_Application::orb()->object_to_string( theObj ); - TCollection_AsciiString asciiIOR( strdup( IOR.c_str() ) ); + CORBA::String_var IOR = SalomeApp_Application::orb()->object_to_string( theObj ); + TCollection_AsciiString asciiIOR( (char *)IOR.in() ); GEOM_Client().RemoveShapeFromBuffer( asciiIOR ); if ( !getStudy() || !getStudy()->studyDS() ) return; _PTR(Study) aStudy = getStudy()->studyDS(); - _PTR(SObject) aSObj ( aStudy->FindObjectIOR( IOR ) ); + _PTR(SObject) aSObj ( aStudy->FindObjectIOR( string( IOR ) ) ); if ( !aSObj ) return; diff --git a/src/GEOMGUI/GEOM_Displayer.cxx b/src/GEOMGUI/GEOM_Displayer.cxx index 105d74879..68724bb38 100644 --- a/src/GEOMGUI/GEOM_Displayer.cxx +++ b/src/GEOMGUI/GEOM_Displayer.cxx @@ -174,11 +174,11 @@ static string getEntry( GEOM::GEOM_Object_ptr object ) SalomeApp_Application* app = dynamic_cast( session->activeApplication() ); if ( app ) { - string IOR = app->orb()->object_to_string( object ); - if ( IOR != "" ) + CORBA::String_var IOR = app->orb()->object_to_string( object ); + if ( strcmp(IOR.in(), "") != 0 ) { SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy(); - _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) ); + _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( string(IOR) ) ); if ( SO ) return SO->GetID(); } @@ -196,11 +196,11 @@ static string getName( GEOM::GEOM_Object_ptr object ) SalomeApp_Application* app = dynamic_cast( session->activeApplication() ); if ( app ) { - string IOR = app->orb()->object_to_string( object ); - if ( IOR != "" ) + CORBA::String_var IOR = app->orb()->object_to_string( object ); + if ( strcmp(IOR.in(), "") != 0 ) { SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy(); - _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( IOR ) ); + _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( string(IOR) ) ); _PTR(GenericAttribute) anAttr; diff --git a/src/GEOMGUI/GeometryGUI.cxx b/src/GEOMGUI/GeometryGUI.cxx index a3d1796f0..0dca4ab32 100644 --- a/src/GEOMGUI/GeometryGUI.cxx +++ b/src/GEOMGUI/GeometryGUI.cxx @@ -1610,9 +1610,14 @@ void GeometryGUI::onViewManagerRemoved( SUIT_ViewManager* vm ) QString GeometryGUI::engineIOR() const { + QString anIOR = QString::null; if ( !CORBA::is_nil( GetGeomGen() ) ) - return QString( getApp()->orb()->object_to_string( GetGeomGen() ) ); - return QString( "" ); + { + CORBA::String_var objStr = getApp()->orb()->object_to_string( GetGeomGen() ); + anIOR = QString( objStr.in() ); + free( objStr ); + } + return anIOR; } LightApp_Selection* GeometryGUI::createSelection() const diff --git a/src/GEOMGUI/GeometryGUI_Swig.cxx b/src/GEOMGUI/GeometryGUI_Swig.cxx index 0e75e9aec..6eebe4a5d 100644 --- a/src/GEOMGUI/GeometryGUI_Swig.cxx +++ b/src/GEOMGUI/GeometryGUI_Swig.cxx @@ -143,7 +143,8 @@ void GEOM_Swig::createAndDisplayGO (const char* Entry) if (!father) return; if (!father->ComponentIOR(aFatherIOR)) { - aStudyBuilder->LoadWith(father, SalomeApp_Application::orb()->object_to_string(Geom)); + CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string(Geom); + aStudyBuilder->LoadWith(father, objStr.in()); father->ComponentIOR(aFatherIOR); } diff --git a/src/GEOMToolsGUI/GEOMToolsGUI.cxx b/src/GEOMToolsGUI/GEOMToolsGUI.cxx index d79cbceb4..9c96d277c 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI.cxx +++ b/src/GEOMToolsGUI/GEOMToolsGUI.cxx @@ -248,8 +248,8 @@ void GEOMToolsGUI::OnEditDelete() // VSR 17/11/04: check if all objects selected belong to GEOM component --> start // modifications of ASV 01.06.05 QString parentComp = getParentComponent( aStudy, selected ); - const char* geomIOR = app->orb()->object_to_string( GeometryGUI::GetGeomGen() ); - QString geomComp = getParentComponent( aStudy->FindObjectIOR( geomIOR ) ); + CORBA::String_var geomIOR = app->orb()->object_to_string( GeometryGUI::GetGeomGen() ); + QString geomComp = getParentComponent( aStudy->FindObjectIOR( geomIOR.in() ) ); if ( parentComp != geomComp ) { SUIT_MessageBox::warn1 ( app->desktop(), diff --git a/src/GEOM_I/GEOM_Gen_i.cc b/src/GEOM_I/GEOM_Gen_i.cc index 38881f2a9..ea5feedf4 100644 --- a/src/GEOM_I/GEOM_Gen_i.cc +++ b/src/GEOM_I/GEOM_Gen_i.cc @@ -119,7 +119,7 @@ char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject, GEOM::GEOM_Object_var obj = GetObject(anObject->GetDocID(), anEntry.ToCString()); CORBA::String_var aPersRefString = _orb->object_to_string(obj); - return strdup(aPersRefString); + return strdup(aPersRefString.in()); } //============================================================================ @@ -173,8 +173,8 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy, } anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR"); SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - char *aGeomObjIOR = _orb->object_to_string(theObject); - anIOR->SetValue(strdup(aGeomObjIOR)); + CORBA::String_var aGeomObjIOR = _orb->object_to_string(theObject); + anIOR->SetValue( aGeomObjIOR .in() ); anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap"); SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr); @@ -229,7 +229,7 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy, aShapeName = "Vertex_"; } //if (strlen(theName) == 0) aShapeName += TCollection_AsciiString(aResultSO->Tag()); - //else aShapeName = TCollection_AsciiString(strdup(theName)); + //else aShapeName = TCollection_AsciiString((char *)theName); // asv : 11.11.04 Introducing a more sofisticated method of name creation, just as // it is done in GUI in GEOMBase::GetDefaultName() - not just add a Tag() == number @@ -339,7 +339,7 @@ CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent, if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true); SALOMEDS::Study_var Study = theComponent->GetStudy(); - TCollection_AsciiString name( strdup(Study->Name()) ); + TCollection_AsciiString name( (char *)(Study->Name() ) ); return true; } @@ -457,7 +457,8 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream, // Add IORAttribute to the Study and set IOR of the created GEOM_Object to it SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSO, "AttributeIOR"); SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - anIOR->SetValue(_orb->object_to_string(obj)); + CORBA::String_var objStr = _orb->object_to_string(obj); + anIOR->SetValue(objStr.in()); // Return the created in the Study SObject return aNewSO._retn(); @@ -482,11 +483,11 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy(SALOMEDS::Study_ptr theStudy, GEOM: if(theObject->_is_nil() || theStudy->_is_nil()) return aResultSO; SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder(); - char* IOR; + CORBA::String_var IOR; if(!theFather->_is_nil()) { IOR = _orb->object_to_string(theFather); - SALOMEDS::SObject_var aFatherSO = theStudy->FindObjectIOR(IOR); + SALOMEDS::SObject_var aFatherSO = theStudy->FindObjectIOR(IOR.in()); if(aFatherSO->_is_nil()) return aResultSO._retn(); aResultSO = aStudyBuilder->NewObject(aFatherSO); //aStudyBuilder->Addreference(aResultSO, aResultSO); @@ -504,7 +505,7 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy(SALOMEDS::Study_ptr theStudy, GEOM: GEOM::GEOM_Object_var anObject = aList[i]; if(anObject->_is_nil()) continue; IOR = _orb->object_to_string(anObject); - SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(IOR); + SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(IOR.in()); if(aSO->_is_nil()) continue; SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aResultSO); aStudyBuilder->Addreference(aSubSO, aSO); @@ -519,8 +520,9 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy(SALOMEDS::Study_ptr theStudy, GEOM: //============================================================================ void GEOM_Gen_i::register_name(char * name) { - GEOM::GEOM_Gen_ptr g = GEOM::GEOM_Gen::_narrow(_this()); - name_service->Register(g, strdup(name)); + CORBA::Object_var obj = _this(); + GEOM::GEOM_Gen_var g = GEOM::GEOM_Gen::_narrow(obj); + name_service->Register(g, name); } //============================================================================ @@ -862,8 +864,9 @@ GEOM::GEOM_Object_ptr GEOM_Gen_i::GetObject (CORBA::Long theStudyID, const char* GEOM_Object_i* servant = new GEOM_Object_i (_poa, engine, handle_object); obj = servant->_this(); - stringIOR = _orb->object_to_string(obj); - handle_object->SetIOR(stringIOR); + CORBA::String_var objStr = _orb->object_to_string(obj); + TCollection_AsciiString anAscii( (char *)objStr.in() ); + handle_object->SetIOR( anAscii ); return obj._retn(); } diff --git a/src/GEOM_I/GEOM_IOperations_i.cc b/src/GEOM_I/GEOM_IOperations_i.cc index f676df98c..89b7fc5f8 100644 --- a/src/GEOM_I/GEOM_IOperations_i.cc +++ b/src/GEOM_I/GEOM_IOperations_i.cc @@ -38,16 +38,6 @@ GEOM_IOperations_i::GEOM_IOperations_i(PortableServer::POA_ptr thePOA, GEOM::GEOM_Gen_ptr theEngine, ::GEOM_IOperations* theImpl) :SALOME::GenericObj_i( thePOA ), _impl(theImpl), _engine(theEngine) { - // Win32 porting: the next line is dangerous - GEOM_IOperations_i is an intermediate - // base class, therefore is not completely constructed here -> - // passing it to activate_object() leads to unpredictable behavior - // resulted from memory corruption ( Rational Purify reports ABR errors ). - // Moreover, all GEOM_IxxxOperation_i servant classes are activated implicitly - // by GEOM_Gen_i::GetxxxOperations() methods. - // Therefore, this line is commented. - // In case if does not have ImplicitActivation policy, then - // activate_object() calls will be necessary in all GEOM_IxxxOperation_i constructors! - //thePOA->activate_object(this); } //============================================================================= diff --git a/src/GEOM_I/GEOM_Object_i.cc b/src/GEOM_I/GEOM_Object_i.cc index 62aa57a71..dce4e328b 100644 --- a/src/GEOM_I/GEOM_Object_i.cc +++ b/src/GEOM_I/GEOM_Object_i.cc @@ -52,7 +52,6 @@ GEOM_Object_i::GEOM_Object_i (PortableServer::POA_ptr thePOA, GEOM::GEOM_Gen_ptr Handle(GEOM_Object) theImpl) : SALOME::GenericObj_i( thePOA ), _engine(theEngine), _impl(theImpl) { - thePOA->activate_object(this); } //============================================================================= @@ -75,7 +74,8 @@ char* GEOM_Object_i::GetEntry() const TDF_Label& aLabel = _impl->GetEntry(); TCollection_AsciiString anEntry; TDF_Tool::Entry(aLabel, anEntry); - return CORBA::string_dup(anEntry.ToCString()); + const char* anEntstr = anEntry.ToCString(); + return CORBA::string_dup(anEntstr); } //============================================================================= @@ -130,7 +130,8 @@ void GEOM_Object_i::SetName(const char* theName) char* GEOM_Object_i::GetName() { char* aName = _impl->GetName(); - if(aName) return strdup(aName); + if (aName) + return aName; // this is already copy of pointer (see implementation of _impl) return strdup(""); } diff --git a/src/GEOM_I_Superv/GEOM_Superv_i.cc b/src/GEOM_I_Superv/GEOM_Superv_i.cc index 8dbfaf982..2f4d96bf1 100644 --- a/src/GEOM_I_Superv/GEOM_Superv_i.cc +++ b/src/GEOM_I_Superv/GEOM_Superv_i.cc @@ -119,7 +119,7 @@ void GEOM_Superv_i::SetStudyID( CORBA::Long theId ) if ( isNewStudy(myLastStudyID,myStudyID) ) { if (CORBA::is_nil(myGeomEngine)) setGeomEngine(); - string anEngine = _orb->object_to_string( myGeomEngine ); + CORBA::String_var anEngine = _orb->object_to_string( myGeomEngine ); CORBA::Object_var anObj = name_service->Resolve("/myStudyManager"); if ( !CORBA::is_nil(anObj) ) { @@ -130,7 +130,7 @@ void GEOM_Superv_i::SetStudyID( CORBA::Long theId ) _PTR(SComponent) aSCO = aDSStudy->FindComponent(myGeomEngine->ComponentDataType()); if ( aSCO ) { _PTR(StudyBuilder) aBuilder = aDSStudy->NewBuilder(); - if ( aBuilder ) aBuilder->LoadWith( aSCO, anEngine ); + if ( aBuilder ) aBuilder->LoadWith( aSCO, string( anEngine.in() ) ); } } } diff --git a/src/GroupGUI/GroupGUI_GroupDlg.cxx b/src/GroupGUI/GroupGUI_GroupDlg.cxx index daa66c165..cf55174ca 100644 --- a/src/GroupGUI/GroupGUI_GroupDlg.cxx +++ b/src/GroupGUI/GroupGUI_GroupDlg.cxx @@ -606,8 +606,10 @@ void GroupGUI_GroupDlg::highlightSubShapes() return; Standard_Boolean isOk; + char* objIOR = GEOMBase::GetIORFromObject( myMainObj ); Handle(GEOM_AISShape) aSh = - GEOMBase::ConvertIORinGEOMAISShape( GEOMBase::GetIORFromObject( myMainObj ), isOk, true ); + GEOMBase::ConvertIORinGEOMAISShape( objIOR, isOk, true ); + free( objIOR ); if ( !isOk || aSh.IsNull() ) return; @@ -703,7 +705,9 @@ bool GroupGUI_GroupDlg::execute( ObjectList& objects ) SalomeApp_Study* study = getStudy(); if ( study ) { - string IOR = GEOMBase::GetIORFromObject( aGroup ); + char* objIOR = GEOMBase::GetIORFromObject( aGroup ); + string IOR( objIOR ); + free( objIOR ); if ( IOR != "" ) { _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) ); if ( SO ) { diff --git a/src/RepairGUI/RepairGUI_GlueDlg.cxx b/src/RepairGUI/RepairGUI_GlueDlg.cxx index bcdb30715..1b2407c42 100644 --- a/src/RepairGUI/RepairGUI_GlueDlg.cxx +++ b/src/RepairGUI/RepairGUI_GlueDlg.cxx @@ -297,15 +297,15 @@ void RepairGUI_GlueDlg::clearShapeBufferLocal( GEOM::GEOM_Object_ptr theObj ) if ( CORBA::is_nil( theObj ) ) return; - string IOR = myGeomGUI->getApp()->orb()->object_to_string( theObj ); - TCollection_AsciiString asciiIOR( strdup( IOR.c_str() ) ); + CORBA::String_var IOR = myGeomGUI->getApp()->orb()->object_to_string( theObj ); + TCollection_AsciiString asciiIOR( (char *)( IOR.in() ) ); myGeomGUI->GetShapeReader().RemoveShapeFromBuffer( asciiIOR ); if ( !getStudy() || !( getStudy()->studyDS() ) ) return; _PTR(Study) aStudy = getStudy()->studyDS(); - _PTR(SObject) aSObj ( aStudy->FindObjectIOR( IOR ) ); + _PTR(SObject) aSObj ( aStudy->FindObjectIOR( string( IOR.in() ) ) ); if ( !aSObj ) return;