Skip to content

Commit aecbe9b

Browse files
committed
Fix memory corruption in reader initialization.
For arrays, CreateProxy() can add to fValues which invalidates iterators. Use stable, index-based iteration instead.
1 parent e2c5e87 commit aecbe9b

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

tree/treeplayer/src/TTreeReader.cxx

+8-6
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,14 @@ TTreeReader::EEntryStatus TTreeReader::SetEntryBase(Long64_t entry, Bool_t local
392392
fMostRecentTreeNumber = fTree->GetTreeNumber();
393393

394394
if (!fProxiesSet) {
395-
// Tell readers we now have a tree
396-
for (std::deque<ROOT::Internal::TTreeReaderValueBase*>::const_iterator
397-
i = fValues.begin(); i != fValues.end(); ++i) { // Iterator end changes when parameterized arrays are read
398-
(*i)->CreateProxy();
399-
400-
if (!(*i)->GetProxy()){
395+
// Tell readers we now have a tree.
396+
// fValues gets insertions during this loop (when parameterized arrays are read),
397+
// invalidating iterators. Use old-school counting instead.
398+
for (size_t i = 0; i < fValues.size(); ++i) {
399+
ROOT::Internal::TTreeReaderValueBase* reader = fValues[i];
400+
reader->CreateProxy();
401+
402+
if (!reader->GetProxy()){
401403
fEntryStatus = kEntryDictionaryError;
402404
return fEntryStatus;
403405
}

0 commit comments

Comments
 (0)