Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"leaked" Property list in nc4_open_file in hdf5open.c #2723

Closed
planetMDX opened this issue Jul 21, 2023 · 2 comments
Closed

"leaked" Property list in nc4_open_file in hdf5open.c #2723

planetMDX opened this issue Jul 21, 2023 · 2 comments

Comments

@planetMDX
Copy link

version: v4.9.2
hdf5: 1.14.1-2
gcc version 13.1.1
os: arch linux
hdf5open

 {
      hid_t pid;
      unsigned int crt_order_flags;
      if ((pid = H5Fget_create_plist(h5->hdfid)) < 0)
          BAIL(NC_EHDFERR);
      if (H5Pget_attr_creation_order(pid, &crt_order_flags) < 0)
          BAIL(NC_EHDFERR);
      if (!(crt_order_flags & H5P_CRT_ORDER_TRACKED)) {
	  nc4_info->no_attr_create_order = NC_TRUE;
      }
    }

is missing a H5Pclose on the pid.

#include <H5public.h>
#include <netcdf.h>
#include <stdio.h>
#include <stdlib.h>
#include <hdf5.h>
#ifndef ITERATIONS_DEFAULT
#define ITERATIONS_DEFAULT 200
#endif
#ifndef NETCDF_FILEPATH_DEFAULT
#define NETCDF_FILEPATH_DEFAULT                                                \
    "/path/to/OMI-Aura_L2-example.nc"
#endif
int main(void) {
    int iterations = ITERATIONS_DEFAULT;
    H5open();
    nc_initialize();
    const char *netcdf_file_path = NETCDF_FILEPATH_DEFAULT;
    printf("iterations: %d\tfilepath: %s\n", iterations, netcdf_file_path);
    setenv("HDF5_USE_FILE_LOCKING", "FALSE", 1);
    for (int c = 0; c < iterations; ++c) {
        int nid = 0;
        nc_open(netcdf_file_path, 0, &nid);
        nc_close(nid);
    }
    _Exit(0);
}

produces this run-val2.log valgrind log when compiled under -O0

line 39379 to 39391 are of relevance here:

==2241928== 78,568 bytes in 1,403 blocks are still reachable in loss record 2,875 of 2,878
==2241928==    at 0x4841848: malloc (vg_replace_malloc.c:431)
==2241928==    by 0x4EAD1A7: H5MM_malloc (in /home/plane/opt/lib/hdf5/lib/libhdf5.so.310.1.0)
==2241928==    by 0x4D9DD97: H5FL__malloc (in /home/plane/opt/lib/hdf5/lib/libhdf5.so.310.1.0)
==2241928==    by 0x4D9E649: H5FL_reg_malloc (in /home/plane/opt/lib/hdf5/lib/libhdf5.so.310.1.0)
==2241928==    by 0x5053AA3: H5SL__new_node (in /home/plane/opt/lib/hdf5/lib/libhdf5.so.310.1.0)
==2241928==    by 0x505A789: H5SL__insert_common (in /home/plane/opt/lib/hdf5/lib/libhdf5.so.310.1.0)
==2241928==    by 0x505B59E: H5SL_insert (in /home/plane/opt/lib/hdf5/lib/libhdf5.so.310.1.0)
==2241928==    by 0x4FB01CA: H5P_copy_plist (in /home/plane/opt/lib/hdf5/lib/libhdf5.so.310.1.0)
==2241928==    by 0x51F9654: H5VL__native_file_get (in /home/plane/opt/lib/hdf5/lib/libhdf5.so.310.1.0)
==2241928==    by 0x51CB240: H5VL__file_get (in /home/plane/opt/lib/hdf5/lib/libhdf5.so.310.1.0)
==2241928==    by 0x51CB442: H5VL_file_get (in /home/plane/opt/lib/hdf5/lib/libhdf5.so.310.1.0)
==2241928==    by 0x4CF41BC: H5Fget_create_plist (in /home/plane/opt/lib/hdf5/lib/libhdf5.so.310.1.0)
==2241928==    by 0x49043E6: NC4_hdf5get_superblock (nc4hdf.c:2489)
==2241928==    by 0x4904C9B: NC4_read_provenance (nc4info.c:199)
==2241928==    by 0x490D87F: nc4_open_file (hdf5open.c:964)
==2241928==    by 0x490D9D1: NC4_open (hdf5open.c:1040)
==2241928==    by 0x48893A9: NC_open (dfile.c:2172)
==2241928==    by 0x48881ED: nc_open (dfile.c:668)
==2241928==    by 0x10922B: main (test_.c:22)

while if there is an H5Pclose earlier, valgrind produces something like this: run-val.fixed.log, which doesn't feature such a section. Also peak memory usage is down by ~0.2MB under these conditions on my machine.

@DennisHeimbigner
Copy link
Collaborator

Good catch, thanks.

DennisHeimbigner added a commit to DennisHeimbigner/netcdf-c that referenced this issue Jul 23, 2023
re: Issue Unidata#2723

H/T to Roland Ambs for finding a memory leak where an allocated
HDF5 plist is not being reclaimed.
@DennisHeimbigner
Copy link
Collaborator

Fixed by PR #2725

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants