diff --git a/tree/tree/test/TBranch.cxx b/tree/tree/test/TBranch.cxx index 5290046098c77..04c2c1b261c41 100644 --- a/tree/tree/test/TBranch.cxx +++ b/tree/tree/test/TBranch.cxx @@ -234,4 +234,29 @@ TEST_F(TBranchTest, branchInheritsCompression) { for(int mode = 4; mode >= 0; --mode) ASSERT_TRUE(nocomp(mode)) << "Failed for mode: " << mode; +} + +// Inspired by issue #8027 +TEST(Regression, InvalidRead) +{ + const char *ofileName = "test_8027.root"; + struct PathRAII { + std::string fPath; + PathRAII(const char *path) : fPath(path) {} + ~PathRAII() { std::remove(fPath.c_str()); } + }; + PathRAII pr(ofileName); + std::unique_ptr tf{TFile::Open(ofileName, "RECREATE")}; + auto t = new TTree("tree", "tree"); + + auto f = new TNamed("foo", "bar"); + auto b = t->Branch("FileMetaData", &f); + + delete f; + f = nullptr; + b->SetAddress(nullptr); + + t->Fill(); + t->Write(); + tf->Close(); } \ No newline at end of file