Skip to content

Commit 9540d63

Browse files
committed
Fix memleaks due to unmanaged ExpandPathName
Signed-off-by: Felix Schlepper <felix.schlepper@cern.ch>
1 parent 6a773be commit 9540d63

13 files changed

Lines changed: 81 additions & 40 deletions

File tree

Common/Field/src/MagFieldFast.cxx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,11 @@ MagFieldFast::MagFieldFast(float factor, int nomField, const string inpFmt) : mF
6161
bool MagFieldFast::LoadData(const string inpFName)
6262
{
6363
// load field from text file
64-
65-
std::ifstream in(gSystem->ExpandPathName(inpFName.data()), std::ifstream::in);
64+
TString sName(inpFName);
65+
if (gSystem->ExpandPathName(sName)) {
66+
LOG(fatal) << "Failed to expand file name " << inpFName;
67+
}
68+
std::ifstream in(sName.Data(), std::ifstream::in);
6669
if (in.fail()) {
6770
LOG(fatal) << "Failed to open file " << inpFName;
6871
return false;

Common/Field/src/MagneticField.cxx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
/// \author ruben.shahoyan@cern.ch
1515

1616
#include "Field/MagneticField.h"
17-
#include <TFile.h> // for TFile
18-
#include <TPRegexp.h> // for TPRegexp
19-
#include <TSystem.h> // for TSystem, gSystem
17+
#include <TFile.h> // for TFile
18+
#include <TPRegexp.h> // for TPRegexp
19+
#include <TString.h> // for TString
20+
#include <TSystem.h> // for TSystem, gSystem
2021
#include <fairlogger/Logger.h> // for FairLogger
2122
#include "FairParamList.h"
2223
#include "FairRun.h"
@@ -242,7 +243,8 @@ Bool_t MagneticField::loadParameterization()
242243
LOG(fatal) << "MagneticField::loadParameterization: Field data " << getParameterName()
243244
<< " are already loaded from " << getDataFileName() << "\n";
244245
}
245-
const char* fname = gSystem->ExpandPathName(getDataFileName());
246+
TString fname = getDataFileName();
247+
gSystem->ExpandPathName(fname);
246248
TFile* file = TFile::Open(fname);
247249
if (!file) {
248250
LOG(fatal) << "MagneticField::loadParameterization: Failed to open magnetic field data file " << fname << "\n";

DataFormats/Detectors/FIT/common/include/DataFormatsFIT/LookUpTable.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <Rtypes.h>
2525
#include <iostream>
2626
#include <tuple>
27+
#include <TString.h>
2728
#include <TSystem.h>
2829
#include <map>
2930
#include <string>
@@ -236,7 +237,9 @@ class LookupTableBase
236237
}
237238
inputDir += "/share/Detectors/FT0/files/";
238239
filepath = inputDir + "LookupTable_FT0.json";
239-
filepath = gSystem->ExpandPathName(filepath.data()); // Expand $(ALICE_ROOT) into real system path
240+
TString expandedFilepath = filepath;
241+
gSystem->ExpandPathName(expandedFilepath); // Expand $(ALICE_ROOT) into real system path
242+
filepath = expandedFilepath.Data();
240243
} else {
241244
filepath = pathToFile;
242245
}

Detectors/FIT/FT0/simulation/src/Detector.cxx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,7 @@ void Detector::DefineOpticalProperties()
12681268
inputDir += "/share/Detectors/FT0/files/";
12691269

12701270
TString optPropPath = inputDir + "quartzOptProperties.txt";
1271-
optPropPath = gSystem->ExpandPathName(optPropPath.Data()); // Expand $(ALICE_ROOT) into real system path
1271+
gSystem->ExpandPathName(optPropPath); // Expand $(ALICE_ROOT) into real system path
12721272

12731273
Int_t result = ReadOptProperties(optPropPath.Data());
12741274
if (result < 0) {
@@ -1426,15 +1426,15 @@ void Detector::DefineSim2LUTindex()
14261426
}
14271427
inputDir += "/share/Detectors/FT0/files/";
14281428

1429-
std::string indPath = inputDir + "Sim2DataChannels.txt";
1430-
indPath = gSystem->ExpandPathName(indPath.data()); // Expand $(ALICE_ROOT) into real system path
1429+
TString indPath = inputDir + "Sim2DataChannels.txt";
1430+
gSystem->ExpandPathName(indPath); // Expand $(ALICE_ROOT) into real system path
14311431

14321432
std::ifstream infile;
1433-
infile.open(indPath.data());
1434-
LOG(info) << " file open " << indPath.data();
1433+
infile.open(indPath.Data());
1434+
LOG(info) << " file open " << indPath.Data();
14351435
// Check if file is opened correctly
14361436
if (infile.fail() == true) {
1437-
LOG(error) << "Error opening ascii file (it is probably a folder!): " << indPath.c_str();
1437+
LOG(error) << "Error opening ascii file (it is probably a folder!): " << indPath;
14381438
}
14391439
int fromfile;
14401440
for (int iind = 0; iind < Geometry::Nchannels; iind++) {

Detectors/GlobalTrackingWorkflow/study/src/HistoManager.cxx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <TPaveStats.h>
2323
#include <TROOT.h>
2424
#include <TSystem.h>
25+
#include <TString.h>
2526
#include "Framework/Logger.h"
2627
#include "GlobalTrackingStudy/HistoManager.h"
2728

@@ -384,7 +385,9 @@ void HistoManager::purify(bool emptyToo)
384385

385386
void HistoManager::setFileName(const std::string& name)
386387
{
387-
mDefName = gSystem->ExpandPathName(name.c_str());
388+
TString sName = name;
389+
gSystem->ExpandPathName(sName);
390+
mDefName = sName.Data();
388391
}
389392

390393
void HistoManager::reset()
@@ -401,7 +404,12 @@ void HistoManager::reset()
401404

402405
int HistoManager::load(const std::string& fname, const std::string& dirname)
403406
{
404-
TFile* file = TFile::Open(gSystem->ExpandPathName(fname.c_str()));
407+
TString sName = fname;
408+
if (gSystem->ExpandPathName(sName)) {
409+
LOGP(error, "Cannot expand file name {}", fname);
410+
return 0;
411+
}
412+
TFile* file = TFile::Open(sName);
405413
if (!file) {
406414
LOGP(error, "No file {}", fname);
407415
return 0;

Detectors/ITSMFT/MFT/base/src/Geometry.cxx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
/// \brief Implementation of the Geometry class
1414
/// \author Raphael Tieulent <raphael.tieulent@cern.ch>
1515

16-
#include "TSystem.h"
16+
#include <TString.h>
17+
#include <TSystem.h>
1718

1819
#include <fairlogger/Logger.h>
1920

@@ -128,7 +129,9 @@ void Geometry::build()
128129

129130
// load the detector segmentation
130131
if (!mSegmentation) {
131-
mSegmentation = new Segmentation(gSystem->ExpandPathName("$(VMCWORKDIR)/Detectors/Geometry/MFT/data/Geometry.xml"));
132+
TString sName = "$(VMCWORKDIR)/Detectors/Geometry/MFT/data/Geometry.xml";
133+
gSystem->ExpandPathName(sName);
134+
mSegmentation = new Segmentation(sName);
132135
}
133136

134137
// build the geometry

Detectors/ITSMFT/common/simulation/src/AlpideSimResponse.cxx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "ITSMFTSimulation/AlpideSimResponse.h"
1616
#include "ITSMFTSimulation/DPLDigitizerParam.h"
17+
#include <TString.h>
1718
#include <TSystem.h>
1819
#include <cstdio>
1920
#include <cstddef>
@@ -57,7 +58,9 @@ void AlpideSimResponse::initData(int tableNumber, std::string dataPath, const bo
5758
if (mDataPath.length() && mDataPath.back() != '/') {
5859
mDataPath.push_back('/');
5960
}
60-
mDataPath = gSystem->ExpandPathName(mDataPath.data());
61+
TString expandedDataPath = mDataPath;
62+
gSystem->ExpandPathName(expandedDataPath);
63+
mDataPath = expandedDataPath.Data();
6164
string inpfname = mDataPath + mGridColName;
6265
std::ifstream inpGrid;
6366

Detectors/TOF/calibration/src/TOFFEElightReader.cxx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
#include <TOFCalibration/TOFFEElightReader.h>
1313
#include "Framework/Logger.h"
14-
#include "TSystem.h"
14+
#include <TString.h>
15+
#include <TSystem.h>
1516
#include <fstream>
1617

1718
using namespace o2::tof;
@@ -20,9 +21,10 @@ void TOFFEElightReader::loadFEElightConfig(const char* fileName)
2021
{
2122
// load FEElight config
2223

23-
char* expandedFileName = gSystem->ExpandPathName(fileName);
24+
TString expandedFileName = fileName;
25+
gSystem->ExpandPathName(expandedFileName);
2426
std::ifstream is;
25-
is.open(expandedFileName, std::ios::binary);
27+
is.open(expandedFileName.Data(), std::ios::binary);
2628
mFileLoadBuff.reset(new char[sizeof(o2::tof::TOFFEElightConfig)]);
2729
is.read(mFileLoadBuff.get(), sizeof(o2::tof::TOFFEElightConfig));
2830
is.close();

Generators/src/DecayerPythia8.cxx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "TLorentzVector.h"
1818
#include "TClonesArray.h"
1919
#include "TParticle.h"
20+
#include "TString.h"
2021
#include "TSystem.h"
2122

2223
#include <iostream>
@@ -43,9 +44,10 @@ void DecayerPythia8::Init()
4344
if (param.config[i].empty()) {
4445
continue;
4546
}
46-
std::string config = gSystem->ExpandPathName(param.config[i].c_str());
47+
TString config = param.config[i];
48+
gSystem->ExpandPathName(config);
4749
LOG(info) << "Reading configuration from file: " << config;
48-
if (!mPythia.readFile(config, true)) {
50+
if (!mPythia.readFile(config.Data(), true)) {
4951
LOG(fatal) << "Failed to init \'DecayerPythia8\': problems with configuration file "
5052
<< config;
5153
return;

Generators/src/Generator.cxx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <cmath>
2424
#include "TClonesArray.h"
2525
#include "TParticle.h"
26+
#include "TString.h"
2627
#include "TSystem.h"
2728
#include "TGrid.h"
2829
#include "CCDB/BasicCCDBManager.h"
@@ -117,13 +118,18 @@ bool Generator::initTPCLoopersGen()
117118
{
118119
// Expand all environment paths
119120
const auto& loopersParam = o2::eventgen::GenTPCLoopersParam::Instance();
120-
std::string model_pairs = gSystem->ExpandPathName(loopersParam.model_pairs.c_str());
121-
std::string model_compton = gSystem->ExpandPathName(loopersParam.model_compton.c_str());
122-
std::string nclxrate = gSystem->ExpandPathName(loopersParam.nclxrate.c_str());
123-
const auto& scaler_pair = gSystem->ExpandPathName(loopersParam.scaler_pair.c_str());
124-
const auto& scaler_compton = gSystem->ExpandPathName(loopersParam.scaler_compton.c_str());
125-
const auto& poisson = gSystem->ExpandPathName(loopersParam.poisson.c_str());
126-
const auto& gauss = gSystem->ExpandPathName(loopersParam.gauss.c_str());
121+
auto expandPathName = [](const std::string& path) {
122+
TString expandedPath = path;
123+
gSystem->ExpandPathName(expandedPath);
124+
return std::string(expandedPath.Data());
125+
};
126+
std::string model_pairs = expandPathName(loopersParam.model_pairs);
127+
std::string model_compton = expandPathName(loopersParam.model_compton);
128+
std::string nclxrate = expandPathName(loopersParam.nclxrate);
129+
const std::string scaler_pair = expandPathName(loopersParam.scaler_pair);
130+
const std::string scaler_compton = expandPathName(loopersParam.scaler_compton);
131+
const std::string poisson = expandPathName(loopersParam.poisson);
132+
const std::string gauss = expandPathName(loopersParam.gauss);
127133
const auto& flat_gas = loopersParam.flat_gas;
128134
const auto& colsys = loopersParam.colsys;
129135
if (flat_gas) {

0 commit comments

Comments
 (0)