Skip to content

Commit 51dd775

Browse files
Fix resource leak in Subfiling example programs and tests (#5617)
1 parent 0743df2 commit 51dd775

File tree

5 files changed

+19
-0
lines changed

5 files changed

+19
-0
lines changed

HDF5Examples/C/H5PAR/ph5_subfiling.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ subfiling_write_custom(hid_t fapl_id, int mpi_size, int mpi_rank)
314314

315315
cleanup(EXAMPLE_FILE2, subfiling_fapl);
316316

317+
H5Pclose(subf_config.ioc_fapl_id);
317318
H5Pclose(subfiling_fapl);
318319
}
319320

@@ -484,6 +485,7 @@ subfiling_write_precreate(hid_t fapl_id, int mpi_size, int mpi_rank)
484485

485486
cleanup(EXAMPLE_FILE3, subfiling_fapl);
486487

488+
H5Pclose(subf_config.ioc_fapl_id);
487489
H5Pclose(subfiling_fapl);
488490
}
489491

HDF5Examples/FORTRAN/H5PAR/ph5_f90_subfiling.F90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ SUBROUTINE subfiling_write_custom(fapl_id, mpi_size, mpi_rank)
290290

291291
CALL cleanup(EXAMPLE_FILE, subfiling_fapl)
292292

293+
CALL H5Pclose_f(subf_config%ioc_fapl_id, status)
293294
CALL H5Pclose_f(subfiling_fapl, status)
294295

295296
END SUBROUTINE subfiling_write_custom
@@ -457,6 +458,7 @@ SUBROUTINE subfiling_write_precreate(fapl_id, mpi_size, mpi_rank)
457458

458459
CALL cleanup(EXAMPLE_FILE, subfiling_fapl)
459460

461+
CALL H5Pclose_f(subf_config%ioc_fapl_id, status)
460462
CALL H5Pclose_f(subfiling_fapl, status)
461463

462464
END SUBROUTINE subfiling_write_precreate

src/H5FDsubfiling/H5FDsubfiling.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,12 @@ H5_DLL herr_t H5Pset_fapl_subfiling(hid_t fapl_id, const H5FD_subfiling_config_t
396396
* the default values and then calling H5Pset_fapl_subfiling() with the configured
397397
* H5FD_subfiling_config_t structure.
398398
*
399+
* The `ioc_fapl_id` field of the returned structure will be the ID of a copied or
400+
* newly-created property list which should be closed with H5Pclose() when the
401+
* configuration structure is no longer in use. An application should also be sure to
402+
* close this property list ID first if a different property list ID will be assigned
403+
* to the `ioc_fapl_id` field.
404+
*
399405
* \note H5Pget_fapl_subfiling() returns the #H5FD_SUBFILING driver properties as they
400406
* were initially set for the File Access Property List using H5Pset_fapl_subfiling().
401407
* Alternatively, the driver properties can be modified at runtime according to values

testpar/t_subfiling_vfd.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ create_subfiling_ioc_fapl(MPI_Comm comm, MPI_Info info, bool custom_config,
182182

183183
if (H5Pset_fapl_subfiling(ret_value, &subfiling_conf) < 0)
184184
TEST_ERROR;
185+
186+
if (H5Pclose(subfiling_conf.ioc_fapl_id < 0))
187+
TEST_ERROR;
185188
}
186189

187190
return ret_value;

testpar/t_vfd.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,12 @@ setup_vfd_test_file(int file_name_id, char *file_name, int mpi_size, H5FD_mpio_x
477477
}
478478

479479
/* Assign the IOC fapl as the underlying VPD */
480+
if ((pass) && (H5Pclose(subfiling_conf.ioc_fapl_id) == FAIL)) {
481+
482+
pass = false;
483+
failure_mssg = "Can't close default IOC FAPL.";
484+
}
485+
480486
subfiling_conf.ioc_fapl_id = ioc_fapl;
481487

482488
/* Now we can set the SUBFILING fapl before returning. */

0 commit comments

Comments
 (0)