fix for void operator delete... called on unallocated object
Cleaning what should be different place triggered this warning here ...
In file included from /data/christos/Athena-git/athena/Tracking/TrkEvent/TrkParameters/TrkParameters/TrackParameters.h:12,
from /cvmfs/atlas-nightlies.cern.ch/repo/sw/master_Athena_x86_64-centos7-gcc11-opt/2022-11-28T2101/Athena/23.0.11/InstallArea/x86_64-centos7-gcc11-opt/src/Tracking/TrkExtrapolation/TrkExInterfaces/TrkExInterfaces/HelperStructs.h:8,
from /cvmfs/atlas-nightlies.cern.ch/repo/sw/master_Athena_x86_64-centos7-gcc11-opt/2022-11-28T2101/Athena/23.0.11/InstallArea/x86_64-centos7-gcc11-opt/src/Tracking/TrkExtrapolation/TrkExInterfaces/TrkExInterfaces/ITimedExtrapolator.h:15,
from /data/christos/Athena-git/athena/Simulation/FastShower/FastCaloSim/FastCaloSim/FastShowerCellBuilderTool.h:22,
from /data/christos/Athena-git/athena/Simulation/FastShower/FastCaloSim/src/FastShowerCellBuilderTool.cxx:5:
In destructor 'Trk::CurvilinearParametersT<DIM, T, S>::~CurvilinearParametersT() [with int DIM = 5; T = Trk::Charged; S = Trk::PlaneSurface]',
inlined from 'void std::default_delete<_Tp>::operator()(_Tp*) const [with _Tp = const Trk::ParametersBase<5, Trk::Charged>]' at /cvmfs/sft.cern.ch/lcg/releases/gcc/11.2.0-8a51a/x86_64-centos7/include/c++/11.2.0/bits/unique_ptr.h:85:2,
inlined from 'void std::__uniq_ptr_impl<_Tp, _Dp>::reset(std::__uniq_ptr_impl<_Tp, _Dp>::pointer) [with _Tp = const Trk::ParametersBase<5, Trk::Charged>; _Dp = std::default_delete<const Trk::ParametersBase<5, Trk::Charged> >]' at /cvmfs/sft.cern.ch/lcg/releases/gcc/11.2.0-8a51a/x86_64-centos7/include/c++/11.2.0/bits/unique_ptr.h:182:16,
inlined from 'void std::unique_ptr<_Tp, _Dp>::reset(std::unique_ptr<_Tp, _Dp>::pointer) [with _Tp = const Trk::ParametersBase<5, Trk::Charged>; _Dp = std::default_delete<const Trk::ParametersBase<5, Trk::Charged> >]' at /cvmfs/sft.cern.ch/lcg/releases/gcc/11.2.0-8a51a/x86_64-centos7/include/c++/11.2.0/bits/unique_ptr.h:456:12,
inlined from 'std::vector<Trk::HitInfo>* FastShowerCellBuilderTool::caloHits(const HepMC::GenParticle&) const' at /data/christos/Athena-git/athena/Simulation/FastShower/FastCaloSim/src/FastShowerCellBuilderTool.cxx:2474:20:
/data/christos/Athena-git/athena/Tracking/TrkEvent/TrkParametersBase/TrkParametersBase/CurvilinearParametersT.h:97:11: warning: 'void operator delete(void*, std::size_t)' called on unallocated object 'inputPar' [-Wfree-nonheap-object]
97 | virtual ~CurvilinearParametersT() = default;
| ^
/data/christos/Athena-git/athena/Simulation/FastShower/FastCaloSim/src/FastShowerCellBuilderTool.cxx: In member function 'std::vector<Trk::HitInfo>* FastShowerCellBuilderTool::caloHits(const HepMC::GenParticle&) const':
/data/christos/Athena-git/athena/Simulation/FastShower/FastCaloSim/src/FastShowerCellBuilderTool.cxx:2392:30: note: declared here
2392 | Trk::CurvilinearParameters inputPar(pos,mom,charge);
In human terms
if(caloEntry.get()==&inputPar) {
ATH_MSG_DEBUG("Use clone of inputPar as caloEntry");
caloEntry=inputPar.uniqueClone();
}
- caloEntry is a unique_ptr
- inputPar is a local/ stack allocated variable
- The something else I was doing prb allowed gcc to see through what was going on here (not sure why it could not before ...).
- Prb allowed /dissalowed some optimisation ...
- The issue is that if the
unique_ptr
actually holds the address of the local variable, - setting / resetting the
unique_ptr
means deleting what it holds. - which in this case is a stack allocated variable (this is what gcc could not see before?)
Now in reality we do the clone above . The extrapolator calls will return us a fresh ptr and if we do not run them we clone. So we should not ever have this being true ...
Edited by Christos Anastopoulos