Skip to content

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.

Merge request reports