Skip to content

[RF] Fix memory leak of ConcatFileName return value in RooWorkspace #18730

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
May 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 23 additions & 32 deletions roofit/roofitcore/src/RooWorkspace.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1481,6 +1481,25 @@ std::list<TObject*> RooWorkspace::allGenericObjects() const
}


namespace {

std::string findFileInPath(std::string const &file, std::list<std::string> const &dirList)
{
// Check list of additional paths
for (std::string const &diter : dirList) {

char *cpath = gSystem->ConcatFileName(diter.c_str(), file.c_str());
std::string path = cpath;
delete[] cpath;
if (!gSystem->AccessPathName(path.c_str())) {
// found file
return path;
}
}
return "";
}

} // namespace


////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1548,29 +1567,15 @@ bool RooWorkspace::CodeRepo::autoImportClass(TClass* tc, bool doReplace)
// If not, scan through list of 'class declaration' paths in RooWorkspace
if (gSystem->AccessPathName(declfile.c_str())) {

// Check list of additional declaration paths
list<string>::iterator diter = RooWorkspace::_classDeclDirList.begin() ;

while(diter!= RooWorkspace::_classDeclDirList.end()) {

declpath = gSystem->ConcatFileName(diter->c_str(),declfile.c_str()) ;
if (!gSystem->AccessPathName(declpath.c_str())) {
// found declaration file
break ;
}
// cleanup and continue ;
declpath.clear();

++diter ;
}
declpath = findFileInPath(declfile, RooWorkspace::_classDeclDirList);

// Header file cannot be found anywhere, warn user and abort operation
if (declpath.empty()) {
oocoutW(_wspace,ObjectHandling) << "RooWorkspace::autoImportClass(" << _wspace->GetName() << ") WARNING Cannot access code of class "
<< tc->GetName() << " because header file " << declfile << " is not found in current directory nor in $ROOTSYS" ;
if (!_classDeclDirList.empty()) {
ooccoutW(_wspace,ObjectHandling) << ", nor in the search path " ;
diter = RooWorkspace::_classDeclDirList.begin() ;
auto diter = RooWorkspace::_classDeclDirList.begin() ;

while(diter!= RooWorkspace::_classDeclDirList.end()) {

Expand All @@ -1593,29 +1598,15 @@ bool RooWorkspace::CodeRepo::autoImportClass(TClass* tc, bool doReplace)
// If not, scan through list of 'class implementation' paths in RooWorkspace
if (gSystem->AccessPathName(implfile.c_str())) {

// Check list of additional declaration paths
list<string>::iterator iiter = RooWorkspace::_classImplDirList.begin() ;

while(iiter!= RooWorkspace::_classImplDirList.end()) {

implpath = gSystem->ConcatFileName(iiter->c_str(),implfile.c_str()) ;
if (!gSystem->AccessPathName(implpath.c_str())) {
// found implementation file
break ;
}
// cleanup and continue ;
implpath.clear();

++iiter ;
}
implpath = findFileInPath(implfile, RooWorkspace::_classImplDirList);

// Implementation file cannot be found anywhere, warn user and abort operation
if (implpath.empty()) {
oocoutW(_wspace,ObjectHandling) << "RooWorkspace::autoImportClass(" << _wspace->GetName() << ") WARNING Cannot access code of class "
<< tc->GetName() << " because implementation file " << implfile << " is not found in current directory nor in $ROOTSYS" ;
if (!_classDeclDirList.empty()) {
ooccoutW(_wspace,ObjectHandling) << ", nor in the search path " ;
iiter = RooWorkspace::_classImplDirList.begin() ;
auto iiter = RooWorkspace::_classImplDirList.begin() ;

while(iiter!= RooWorkspace::_classImplDirList.end()) {

Expand Down
Loading