From 70d206ebe9962caf622d1583f0ad4d19cc77b193 Mon Sep 17 00:00:00 2001 From: vsr Date: Tue, 19 Apr 2011 13:20:21 +0000 Subject: [PATCH] Fix memory leaks on study closing --- src/VISU_I/VISU_Gen_i.cc | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/VISU_I/VISU_Gen_i.cc b/src/VISU_I/VISU_Gen_i.cc index 15068b88..051791fa 100644 --- a/src/VISU_I/VISU_Gen_i.cc +++ b/src/VISU_I/VISU_Gen_i.cc @@ -1550,9 +1550,24 @@ namespace VISU VISU_Gen_i ::Close(SALOMEDS::SComponent_ptr theComponent) { - if ( !CORBA::is_nil( myStudyDocument ) && !CORBA::is_nil( theComponent ) && - myStudyDocument->StudyId() == theComponent->GetStudy()->StudyId()) - myStudyDocument = SALOMEDS::Study::_nil(); + if ( !CORBA::is_nil( theComponent ) ) { + SALOMEDS::Study_var aStudy = theComponent->GetStudy(); + // 1. Decrement reference counter for published GenericObj-based servants + SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator( theComponent ); + anIter->InitEx( true ); + for ( ; anIter->More(); anIter->Next() ) { + SALOMEDS::SObject_var aSObject = anIter->Value(); + if ( CORBA::is_nil( aSObject ) ) continue; + CORBA::Object_var anObject = aSObject->GetObject(); + if ( CORBA::is_nil( anObject ) ) continue; + SALOME::GenericObj_var aGenericObj = SALOME::GenericObj::_narrow( anObject ); + if ( !CORBA::is_nil( aGenericObj ) ) aGenericObj->UnRegister(); + } + + if ( !CORBA::is_nil( myStudyDocument ) && !CORBA::is_nil( aStudy ) && + myStudyDocument->StudyId() == aStudy->StudyId() ) + myStudyDocument = SALOMEDS::Study::_nil(); + } } -- 2.39.2