change HDF5's file open options to close all sub-file objects when a file is closed

Create issue
Issue #1032 closed
Roland Haas created an issue

this is strictly speaking not necessary, since any need for it is caused by a HDF5 object leak. On the other hand it does not hurt either additionally one could overload H5Fclose and warn the user when there are still open objects when a file is closed, ie:

 // Close HDF5 file checking for leaked objects
 static herr_t H5Fclose (hid_t file)

   herr_t retval;
   int error_count = 0;

   hsize_t objectcount;
   HDF5_ERROR (objectcount = H5Fget_obj_count(file,
                                              H5F_OBJ_ALL | H5F_OBJ_LOCAL));
   if (objectcount > 1) {
     std::vector<char> fn;
     hsize_t sz_fn;

     HDF5_ERROR (sz_fn = H5Fget_name(file, NULL, 0));
     HDF5_ERROR (H5Fget_name(file, &fn[0], fn.size()));

                 "%d open HDF5 objects when closing file '%s'",
                 int(objectcount)-1, &fn[0]);
   HDF5_ERROR (retval = ::H5Fclose (file));

   return retval;

Keyword: CarpetIOHDF5

Comments (4)

  1. Roland Haas reporter
    • changed status to resolved
    • removed comment

    I applied the patch (but not the overloaded HDF5 close function) as Carpet hash f0dc71726af0 "CarpetIOHDF5: close all HDF5 objects when closing a file".

  2. Log in to comment