Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[treeplayer] Fix memory management of C-style array branches in test #16501

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
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
41 changes: 33 additions & 8 deletions tree/treeplayer/test/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,39 @@
#define TTREEREADER_LEAF_TEST_DATA

#include <vector>
struct Data {
unsigned int fUSize;
int fSize;
double* fArray; //[fSize]
float* fUArray; //[fUSize]
std::vector<double> fVec;
Double32_t fDouble32;
Float16_t fFloat16;
class Data {
unsigned int fUSize{};
int fSize{};
double *fArray{nullptr}; //[fSize]
float *fUArray{nullptr}; //[fUSize]
std::vector<double> fVec{};
Double32_t fDouble32{};
Float16_t fFloat16{};

public:
Data() = default;
Data(const Data &) = delete;
Data &operator=(const Data &) = delete;
Data(Data &&) = delete;
Data &operator=(Data &&) = delete;
~Data()
{
delete[] fArray;
fArray = nullptr;
delete[] fUArray;
fUArray = nullptr;
}
void Init()
{
fUSize = 2;
fSize = 4;
fArray = new double[4]{12., 13., 14., 15.};
fUArray = new float[2]{42., 43.};
fVec = {17., 18., 19., 20., 21., 22.};
fDouble32 = 17.;
fFloat16 = 44.;
}
std::vector<double> &GetVecMember() { return fVec; }
};

struct V {
Expand Down
22 changes: 8 additions & 14 deletions tree/treeplayer/test/leafs.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -84,32 +84,26 @@ TEST(TTreeReaderLeafs, LeafListCaseA) {
EXPECT_EQ(Bool, *trBool);
}



std::unique_ptr<TTree> CreateTree() {
std::unique_ptr<TTree> CreateTree()
{
TInterpreter::EErrorCode error = TInterpreter::kNoError;
gInterpreter->ProcessLine("#include \"data.h\"", &error);
if (error != TInterpreter::kNoError)
return {};

Data data;
data.Init();
auto &vecDataMember = data.GetVecMember();
auto tree = std::make_unique<TTree>("T", "test tree");
tree->Branch("Data", &data);
data.fArray = new double[4]{12., 13., 14., 15.};
data.fSize = 4;
data.fUArray = new float[2]{42., 43.};
data.fUSize = 2;
data.fVec = { 17., 18., 19., 20., 21., 22.};
data.fDouble32 = 17.;
data.fFloat16 = 44.;
tree->Fill();

data.fVec.clear();
data.fVec.resize(3210, 1001.f); // ROOT-8747
vecDataMember.clear();
vecDataMember.resize(3210, 1001.f); // ROOT-8747
tree->Fill();

data.fVec.clear();
data.fVec.resize(2, 42.f); // ROOT-8747
vecDataMember.clear();
vecDataMember.resize(2, 42.f); // ROOT-8747
tree->Fill();

tree->ResetBranchAddresses();
Expand Down
Loading