Skip to content
Snippets Groups Projects
Commit 00ae1f03 authored by scott snyder's avatar scott snyder
Browse files

TrkDetDescrUtils: Fix memory leaks

CompactBinnedArray maps bins in some coordinates to a vector of pointers
to objects.  It does not own this objects.

BinnedMaterial uses CompactBinnedArray, with the object in question
being a pair<> object.

When a BinnedMaterial is constructed, it takes a vector of pointers
to these pairs.  It does not take ownership of this pairs, but just
passes them to the CompactBinnedArray.

The callers of BinnedMaterial also do not take ownership of these pairs.
So they are presently leaked.

Further, BinnedMaterial can't just delete them, because these pairs
get shared between multiple BinnedMaterial instances.

We restructure like this.

BinnnedMaterial now gets a vector of pairs, which it saves as a member.
The CompactBinnedArray is then constructed to that it points at the
pairs in this vector.  BinnedMaterial now effectively owns the pairs.
These are now duplicated in each BinnedMaterial, but that should be ok.
We also need to extend CompactBinnedArray so that we can give it
a new vector of object pointers when it is cloned.

cf ATLASRECTS-5831.
parent 21a2e761
No related branches found
No related tags found
No related merge requests found
/*
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
///////////////////////////////////////////////////////////////////
......@@ -41,6 +41,7 @@ public:
/** Implicit constructor */
virtual CompactBinnedArrayT* clone() const = 0;
virtual CompactBinnedArrayT* clone(const std::vector<T*>& ptrs) const = 0;
/** layer bin utility */
virtual const Trk::BinUtility* layerBinUtility(const Amg::Vector3D& gp) const = 0;
......
......@@ -94,6 +94,12 @@ public:
return new CompactBinnedArray1DT(m_arrayObjects, m_array, m_binUtility->clone());
}
CompactBinnedArray1DT* clone(const std::vector<T*>& ptrs) const
{
assert (ptrs.size() == m_arrayObjects.size());
return new CompactBinnedArray1DT(ptrs, m_array, m_binUtility->clone());
}
/**Virtual Destructor*/
~CompactBinnedArray1DT() { delete m_binUtility; }
......
......@@ -103,6 +103,12 @@ public:
return new CompactBinnedArray2DT(m_arrayObjects, m_array, m_binUtility->clone(), m_buVec);
}
CompactBinnedArray2DT* clone(const std::vector<T*>& ptrs) const
{
assert (ptrs.size() == m_arrayObjects.size());
return new CompactBinnedArray2DT(ptrs, m_array, m_binUtility->clone(), m_buVec);
}
/**Virtual Destructor*/
~CompactBinnedArray2DT()
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment