Fixes for some mem-leaks: most changes where pretty basic (i.e. adding deletes).
[u/mrichter/AliRoot.git] / STEER / AliVertex.cxx
index 32e92ff27fee99a64fb0f97658244677e9424cbf..593ff60ed91b00afe804f022920b79a6bde2c0f8 100644 (file)
@@ -63,7 +63,8 @@ AliVertex::AliVertex(const AliVertex &source):
   TNamed(source),
   fSigma(source.GetDispersion()),
   fNContributors(source.GetNContributors()),
-  fNIndices(source.GetNIndices())
+  fNIndices(source.GetNIndices()),
+  fIndices(0x0)
 {
   //
   // Copy constructor
@@ -80,16 +81,18 @@ AliVertex &AliVertex::operator=(const AliVertex &source){
   //
   // assignment operator
   //
-  if(&source == this) return *this;
-  this->SetName(source.GetName());
-  this->SetTitle(source.GetTitle());
-  for(Int_t i=0;i<3;i++)fPosition[i] = source.fPosition[i];
-  fSigma = source.GetDispersion();
-  fNContributors = source.GetNContributors();
-  fNIndices = source.GetNIndices();
-  if(source.fNIndices>0) {
-    fIndices = new UShort_t[fNIndices];
-    memcpy(fIndices,source.fIndices,fNIndices*sizeof(UShort_t));
+  if(&source != this){
+    TNamed::operator=(source);
+    for(Int_t i=0;i<3;i++)fPosition[i] = source.fPosition[i];
+    fSigma = source.GetDispersion();
+    fNContributors = source.GetNContributors();
+    fNIndices = source.GetNIndices();
+    if(fIndices)delete [] fIndices;
+    fIndices = 0;
+    if(fNIndices>0) {
+      fIndices = new UShort_t[fNIndices];
+      memcpy(fIndices,source.fIndices,fNIndices*sizeof(UShort_t));
+    }
   }
   return *this;
 }
@@ -101,6 +104,7 @@ AliVertex::~AliVertex() {
 // Default Destructor
 //
   delete [] fIndices;
+  fIndices = 0;
 }
 //--------------------------------------------------------------------------
 void AliVertex::GetXYZ(Double_t position[3]) const {
@@ -120,6 +124,7 @@ void AliVertex::SetIndices(Int_t nindices,UShort_t *indices) {
 //
   if(fNContributors<1)  { printf("fNContributors<1"); return; }
   fNIndices = nindices;
+  delete [] fIndices;
   fIndices = new UShort_t[fNIndices];
   for(Int_t i=0;i<fNIndices;i++) fIndices[i] = indices[i]; 
   return;