Commit 5c029717 authored by Frank Winklmeier's avatar Frank Winklmeier
Browse files

THistSvc: fix memory corruption in deReg(string)

Deregistering a histogram via its name causes a memory corruption (often
resulting in a crash). The problem was that deReg(string) kept checking
the histogram list size while the list is actually being deleted in the
last call to deReg(TObject*).

Also improved the unit test coverage for this case.
parent f92ca666
......@@ -89,7 +89,7 @@ StatusCode THistWrite::initialize()
TH1D* h7 = new TH1D( "TempHist7", "Temporary Tree 7", 100, 0., 100. );
if ( m_ths->regHist( "TempHist7", h7 ).isFailure() ) {
error() << "Couldn't register TempHist6" << endmsg;
error() << "Couldn't register TempHist7" << endmsg;
}
if ( strcmp( h7->GetName(), "TempHist7" ) ) {
error() << "Couldn't use TempHist7 afterwards. getName = " << h7->GetName() << endmsg;
......@@ -277,6 +277,10 @@ StatusCode THistWrite::finalize()
{
info() << "Finalizing..." << endmsg;
if ( m_ths->deReg( "/temp/TempHist6" ).isFailure() ) {
error() << "Failed to deregister histogram TempHist6" << endmsg;
}
TH1* h7 = nullptr;
if ( m_ths->getHist( "TempHist7", h7 ).isFailure() ) {
error() << "Couldn't retrieve TempHist7" << endmsg;
......
......@@ -580,7 +580,9 @@ StatusCode THistSvc::deReg( const std::string& id )
vhid_t* vh = itr->second;
debug() << "will deregister " << vh->size() << " elements of id \"" << id << "\"" << endmsg;
StatusCode sc( StatusCode::SUCCESS );
while ( vh->size() > 0 ) {
// vh will get deleted in deReg once empty, so we cannot query the list size in the loop
size_t vh_size = vh->size();
while ( vh_size-- ) {
if ( deReg( vh->back().obj ).isFailure() ) {
sc = StatusCode::FAILURE;
error() << "Problems deRegistering " << vh->size() << " element of id \"" << id << "\"" << endmsg;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment