]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Fix memory leak when reading AliESDfriends, now deleted for every event
authorkleinb <kleinb@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 28 Nov 2007 17:59:51 +0000 (17:59 +0000)
committerkleinb <kleinb@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 28 Nov 2007 17:59:51 +0000 (17:59 +0000)
STEER/AliESDEvent.cxx
STEER/AliESDInputHandler.cxx

index a8db57e391720dcbf7452e2be68980378a183741..07c51d2f12c2cbe3772a839e1f4a5e81521dac2f 100644 (file)
@@ -286,6 +286,20 @@ void AliESDEvent::Reset()
   // Reset the standard contents
   ResetStdContent(); 
   if(fESDOld)fESDOld->Reset();
+  //  reset for the friends...
+  if(fESDFriendOld){
+    fESDFriendOld->~AliESDfriend();
+    new (fESDFriendOld) AliESDfriend();
+  }
+  // for new data we have to fetch the Pointer from the list 
+  AliESDfriend *fr = (AliESDfriend*)FindListObject("AliESDfriend");
+  if(fr){
+    // delete the content
+    fr->~AliESDfriend();
+    // make a new valid ESDfriend at the same place
+    new (fr) AliESDfriend();
+  }
+
   // call reset for user supplied data?
 }
 
@@ -331,7 +345,7 @@ void AliESDEvent::ResetStdContent()
   if(fEMCALCells)fEMCALCells->DeleteContainer();
   if(fErrorLogs) fErrorLogs->Delete();
 
-  // don't reset fconnected fConnected ;
+  // don't reset fconnected fConnected and the list
 
   fEMCALClusters=0; 
   fFirstEMCALCluster=-1; 
@@ -875,7 +889,9 @@ void AliESDEvent::CreateStdContent()
 }
 
 TObject* AliESDEvent::FindListObject(const char *name){
-  if(fESDObjects)return fESDObjects->FindObject(name);
+  if(fESDObjects){
+    return fESDObjects->FindObject(name);
+  }
   return 0;
 } 
 
@@ -924,7 +940,6 @@ void AliESDEvent::ReadFromTree(TTree *tree){
     Printf("%s %d AliESDEvent::ReadFromTree() Zero Pointer to Tree \n",(char*)__FILE__,__LINE__);
     return;
   }
-
   // load the TTree
   if(!tree->GetTree())tree->LoadTree(0);
 
@@ -952,7 +967,6 @@ void AliESDEvent::ReadFromTree(TTree *tree){
     //  have already connected the old ESD structure... ?
     // reuse also the pointer of the AlliESDEvent
     // otherwise create new ones
-
     TList* connectedList = (TList*) (tree->GetUserInfo()->FindObject("ESDObjectsConnectedToTree"));
   
     if(connectedList){
@@ -964,9 +978,9 @@ void AliESDEvent::ReadFromTree(TTree *tree){
       }
       GetStdContent(); 
 
-      // The pointer to the friend changes when called twice via InitIO. Is this connected to 
-      // the change TChain -> TTree
       
+      // The pointer to the friend changes when called twice via InitIO
+      // since AliESDEvent is deleted
       TObject* oldf = FindListObject("AliESDfriend");
       TObject* newf = 0;
       if(addressF){
index 0c425580a38e58615b03325a55403c1f10e18331..10ddcd1aeb83d8565b291921513930450acc9ebe 100644 (file)
@@ -74,16 +74,16 @@ Bool_t AliESDInputHandler::Init(TTree* tree,  Option_t* /*opt*/)
 Bool_t AliESDInputHandler::BeginEvent(Long64_t /*entry*/)
 {
     // Copy from old to new format if necessary
-    AliESD* old = ((AliESDEvent*) fEvent)->GetAliESDOld();
-    if (old) {
+  AliESD* old = ((AliESDEvent*) fEvent)->GetAliESDOld();
+  if (old) {
        ((AliESDEvent*)fEvent)->CopyFromOldESD();
        old->Reset();
-    }
-    return kTRUE;
+  }
+  return kTRUE;
 }
 
 Bool_t  AliESDInputHandler::FinishEvent(){
-    //
+  if(fEvent)fEvent->Reset();
   return kTRUE;
 }