Skip to content

Commit 6ea3a5d

Browse files
Merge pull request #38858 from peterfpeterson/nxs_h5_descriptor_close
Close the file after parsing it - ornl-next
2 parents 3992f98 + 65ee7e7 commit 6ea3a5d

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Framework/Kernel/src/NexusHDF5Descriptor.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ std::map<std::string, std::set<std::string>> NexusHDF5Descriptor::initAllEntries
9191
try {
9292
fileID = H5::H5File(m_filename, H5F_ACC_RDONLY, H5::FileCreatPropList::DEFAULT, access_plist);
9393
} catch (const H5::FileIException &) {
94+
try {
95+
fileID.close();
96+
} catch (const H5::FileIException &) { /* do nothing */
97+
}
9498
throw std::invalid_argument("ERROR: Kernel::NexusHDF5Descriptor couldn't open hdf5 file " + m_filename + "\n");
9599
}
96100

@@ -105,6 +109,9 @@ std::map<std::string, std::set<std::string>> NexusHDF5Descriptor::initAllEntries
105109
// scan file recursively starting with root group "/"
106110
getGroup(groupID, allEntries, m_firstEntryNameType, 0);
107111

112+
// handle going out of scope should automatically close
113+
fileID.close();
114+
108115
// rely on move semantics
109116
return allEntries;
110117
}

0 commit comments

Comments
 (0)