memory leak in pnetcdf?

Ed Hartnett edwardjameshartnett at gmail.com
Fri Mar 18 12:30:57 CDT 2016


Howdy pnetcdf folk!

While working on the PIO library I found what appears to be a memory leak
in pnetcdf.

I am using version 1.6.1 of the parallel-netcdf library. The following
simple program results in a 5-byte leak, as indicated by the valgrind
output which follows the code listing.

A little experimentation shows that it is the attribute name which is being
copied to a new memory location and then never freed.

Thanks,
Ed


#include <pnetcdf.h>

int
main(int argc, char **argv)
{
    int ncid, ret;

    /* Initialize MPI. */
    if ((ret = MPI_Init(&argc, &argv)))
return ret;

    /* Create the netCDF output file. */
    if ((ret = ncmpi_create(MPI_COMM_WORLD, "test_pnetcdf_leak.nc",
NC_CLOBBER,
   MPI_INFO_NULL, &ncid)))
return ret;

    /* Define a global attribute. */
    int att_val = 42;
    if ((ret = ncmpi_put_att_int(ncid, NC_GLOBAL, "foo1", NC_INT,
1, &att_val)))
return ret;

    /* Close the netCDF file. */
    if ((ret = ncmpi_close(ncid)))
return ret;

    /* Finalize the MPI library. */
    MPI_Finalize();

    return 0;
}




==10556== Memcheck, a memory error detector
==10556== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==10556== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==10556== Command: ./test_pnetcdf_leak
==10556==
==10556== Warning: invalid file descriptor -1 in syscall read()
==10556==
==10556== HEAP SUMMARY:
==10556==     in use at exit: 5 bytes in 1 blocks
==10556==   total heap usage: 631 allocs, 630 frees, 25,236,667 bytes
allocated
==10556==
==10556== 5 bytes in 1 blocks are definitely lost in loss record 1 of 1
==10556==    at 0x4A08B9D: realloc (in
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==10556==    by 0x4C75C68: utf8proc_map (dutf8proc.c:550)
==10556==    by 0x4C75D04: utf8proc_NFC (dutf8proc.c:566)
==10556==    by 0x4D3616B: ncmpii_NC_findattr (in
/usr/local/lib/libnetcdf.so.11.0.0)
==10556==    by 0x4D391C9: ncmpii_put_att (in
/usr/local/lib/libnetcdf.so.11.0.0)
==10556==    by 0x4D3969D: ncmpi_put_att_int (in
/usr/local/lib/libnetcdf.so.11.0.0)
==10556==    by 0x4009A3: main (test_pnetcdf_leak.c:23)
==10556==
==10556== LEAK SUMMARY:
==10556==    definitely lost: 5 bytes in 1 blocks
==10556==    indirectly lost: 0 bytes in 0 blocks
==10556==      possibly lost: 0 bytes in 0 blocks
==10556==    still reachable: 0 bytes in 0 blocks
==10556==         suppressed: 0 bytes in 0 blocks
==10556==
==10556== For counts of detected and suppressed errors, rerun with: -v
==10556== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
[ed at localhost unit]$
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/parallel-netcdf/attachments/20160318/33aa385e/attachment.html>


More information about the parallel-netcdf mailing list