From c4cace9023cb23537a54c912df7b82fbfefa368f Mon Sep 17 00:00:00 2001 From: ferdymercury Date: Wed, 9 Apr 2025 09:57:28 +0200 Subject: [PATCH 1/3] [RF] fix memleak in rooabscollection::find Fixes https://github.com/root-project/root/issues/18322 --- roofit/roofitcore/src/RooAbsCollection.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/roofit/roofitcore/src/RooAbsCollection.cxx b/roofit/roofitcore/src/RooAbsCollection.cxx index 400443057b116..ca3c286580265 100644 --- a/roofit/roofitcore/src/RooAbsCollection.cxx +++ b/roofit/roofitcore/src/RooAbsCollection.cxx @@ -929,6 +929,7 @@ RooAbsArg * RooAbsCollection::find(const char *name) const if (_hashAssistedFind || _list.size() >= _sizeThresholdForMapSearch) { if (!_hashAssistedFind || !_hashAssistedFind->isValid()) { + delete _hashAssistedFind; // needed for the case !_hashAssistedFind->isValid(), does not harm for the case of !_hashAssistedFind _hashAssistedFind = new HashAssistedFind{_list.begin(), _list.end()}; } From 8279043c80282c4959ae375ffbe612193909e158 Mon Sep 17 00:00:00 2001 From: ferdymercury Date: Thu, 10 Apr 2025 07:48:19 +0200 Subject: [PATCH 2/3] [RF] microoptimize, no delete on nullptr --- roofit/roofitcore/src/RooAbsCollection.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/roofit/roofitcore/src/RooAbsCollection.cxx b/roofit/roofitcore/src/RooAbsCollection.cxx index ca3c286580265..421829cfda3a9 100644 --- a/roofit/roofitcore/src/RooAbsCollection.cxx +++ b/roofit/roofitcore/src/RooAbsCollection.cxx @@ -929,7 +929,8 @@ RooAbsArg * RooAbsCollection::find(const char *name) const if (_hashAssistedFind || _list.size() >= _sizeThresholdForMapSearch) { if (!_hashAssistedFind || !_hashAssistedFind->isValid()) { - delete _hashAssistedFind; // needed for the case !_hashAssistedFind->isValid(), does not harm for the case of !_hashAssistedFind + if (_hashAssistedFind) + delete _hashAssistedFind; _hashAssistedFind = new HashAssistedFind{_list.begin(), _list.end()}; } From 6696ce91daa45fe5c266966640f90be65766dedd Mon Sep 17 00:00:00 2001 From: ferdymercury Date: Thu, 10 Apr 2025 07:49:17 +0200 Subject: [PATCH 3/3] Clangformat --- roofit/roofitcore/src/RooAbsCollection.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roofit/roofitcore/src/RooAbsCollection.cxx b/roofit/roofitcore/src/RooAbsCollection.cxx index 421829cfda3a9..4389607df97b8 100644 --- a/roofit/roofitcore/src/RooAbsCollection.cxx +++ b/roofit/roofitcore/src/RooAbsCollection.cxx @@ -930,7 +930,7 @@ RooAbsArg * RooAbsCollection::find(const char *name) const if (_hashAssistedFind || _list.size() >= _sizeThresholdForMapSearch) { if (!_hashAssistedFind || !_hashAssistedFind->isValid()) { if (_hashAssistedFind) - delete _hashAssistedFind; + delete _hashAssistedFind; _hashAssistedFind = new HashAssistedFind{_list.begin(), _list.end()}; }