From 2d8e7b795edce26d4c8568971bb8694222eb5262 Mon Sep 17 00:00:00 2001 From: Bertrand Bellenot Date: Tue, 3 Oct 2023 09:38:18 +0200 Subject: [PATCH 1/2] Fix potential crash of the rreader test on Windows Delete the `TFile` pointers, preventing a potential crash in `TROOT::CloseFiles()` when trying to call the `Close()` method on `TWebSocket`/`TWebFile` via the interpreter `CallFunc_Exec` on Windows (visble with LLVM 16) --- tmva/tmva/test/rreader.cxx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tmva/tmva/test/rreader.cxx b/tmva/tmva/test/rreader.cxx index aa9d7b68b649e..58698e949bdc9 100644 --- a/tmva/tmva/test/rreader.cxx +++ b/tmva/tmva/test/rreader.cxx @@ -53,6 +53,7 @@ void TrainClassificationModel() factory->BookMethod(dataloader, TMVA::Types::kBDT, "BDT", "!V:!H:NTrees=100:MaxDepth=2"); factory->TrainAllMethods(); output->Close(); + delete data; } // Regression @@ -92,6 +93,7 @@ void TrainRegressionModel() factory->BookMethod(dataloader, TMVA::Types::kBDT, "BDTG", "!V:!H:NTrees=100:MaxDepth=2"); factory->TrainAllMethods(); output->Close(); + delete data; } // Multiclass @@ -138,6 +140,7 @@ void TrainMulticlassModel() factory->BookMethod(dataloader, TMVA::Types::kBDT, "BDT", "!V:!H:NTrees=100:MaxDepth=2:BoostType=Grad"); factory->TrainAllMethods(); output->Close(); + delete data; } TEST(RReader, ClassificationGetVariables) From 516d36ccca6dc6516740f1d1365e81e2f1985286 Mon Sep 17 00:00:00 2001 From: Bertrand Bellenot Date: Tue, 3 Oct 2023 11:22:00 +0200 Subject: [PATCH 2/2] Use `std::unique_ptr` instead of deleting the pointers (thanks Jonas) --- tmva/tmva/test/rreader.cxx | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tmva/tmva/test/rreader.cxx b/tmva/tmva/test/rreader.cxx index 58698e949bdc9..235958d502750 100644 --- a/tmva/tmva/test/rreader.cxx +++ b/tmva/tmva/test/rreader.cxx @@ -35,7 +35,7 @@ void TrainClassificationModel() // Open trees with signal and background events const std::string filename = "http://root.cern.ch/files/tmva_class_example.root"; - auto data = TFile::Open(filename.c_str()); + std::unique_ptr data{TFile::Open(filename.c_str())}; auto signal = (TTree *)data->Get("TreeS"); auto background = (TTree *)data->Get("TreeB"); @@ -53,7 +53,6 @@ void TrainClassificationModel() factory->BookMethod(dataloader, TMVA::Types::kBDT, "BDT", "!V:!H:NTrees=100:MaxDepth=2"); factory->TrainAllMethods(); output->Close(); - delete data; } // Regression @@ -78,7 +77,7 @@ void TrainRegressionModel() // Open trees with signal and background events const std::string filename = "http://root.cern.ch/files/tmva_reg_example.root"; - auto data = TFile::Open(filename.c_str()); + std::unique_ptr data{TFile::Open(filename.c_str())}; auto tree = (TTree *)data->Get("TreeR"); // Add variables and register the trees with the dataloader @@ -93,7 +92,6 @@ void TrainRegressionModel() factory->BookMethod(dataloader, TMVA::Types::kBDT, "BDTG", "!V:!H:NTrees=100:MaxDepth=2"); factory->TrainAllMethods(); output->Close(); - delete data; } // Multiclass @@ -118,7 +116,7 @@ void TrainMulticlassModel() // Open trees with signal and background events const std::string filename = "http://root.cern.ch/files/tmva_multiclass_example.root"; - auto data = TFile::Open(filename.c_str()); + std::unique_ptr data{TFile::Open(filename.c_str())}; auto signal = (TTree *)data->Get("TreeS"); auto background0 = (TTree *)data->Get("TreeB0"); auto background1 = (TTree *)data->Get("TreeB1"); @@ -140,7 +138,6 @@ void TrainMulticlassModel() factory->BookMethod(dataloader, TMVA::Types::kBDT, "BDT", "!V:!H:NTrees=100:MaxDepth=2:BoostType=Grad"); factory->TrainAllMethods(); output->Close(); - delete data; } TEST(RReader, ClassificationGetVariables)