<div dir="ltr">Howdy pnetcdf folk!<div><br></div><div>While working on the PIO library I found what appears to be a memory leak in pnetcdf.</div><div><br></div><div>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.</div><div><br></div><div>A little experimentation shows that it is the attribute name which is being copied to a new memory location and then never freed.</div><div><br></div><div>Thanks,</div><div>Ed</div><div><br></div><div><br></div><div><div>#include <pnetcdf.h></div><div><br></div><div>int</div><div>main(int argc, char **argv)</div><div>{</div><div>    int ncid, ret;</div><div>    </div><div>    /* Initialize MPI. */</div><div>    if ((ret = MPI_Init(&argc, &argv)))</div><div><span class="" style="white-space:pre">   </span>return ret;</div><div><br></div><div>    /* Create the netCDF output file. */</div><div>    if ((ret = ncmpi_create(MPI_COMM_WORLD, "<a href="http://test_pnetcdf_leak.nc">test_pnetcdf_leak.nc</a>", NC_CLOBBER,</div><div><span class="" style="white-space:pre">                    </span>    MPI_INFO_NULL, &ncid)))</div><div><span class="" style="white-space:pre">  </span>return ret;</div><div><br></div><div>    /* Define a global attribute. */</div><div>    int att_val = 42;</div><div>    if ((ret = ncmpi_put_att_int(ncid, NC_GLOBAL, "foo1", NC_INT,</div><div><span class="" style="white-space:pre">                                </span> 1, &att_val)))</div><div><span class="" style="white-space:pre">        </span>return ret;</div><div><br></div><div>    /* Close the netCDF file. */</div><div>    if ((ret = ncmpi_close(ncid)))</div><div><span class="" style="white-space:pre">   </span>return ret;</div><div><br></div><div>    /* Finalize the MPI library. */</div><div>    MPI_Finalize();</div><div><br></div><div>    return 0;</div><div>}</div></div><div><br></div><div><br></div><div><br></div><div><br></div><div><div>==10556== Memcheck, a memory error detector</div><div>==10556== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.</div><div>==10556== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info</div><div>==10556== Command: ./test_pnetcdf_leak</div><div>==10556== </div><div>==10556== Warning: invalid file descriptor -1 in syscall read()</div><div>==10556== </div><div>==10556== HEAP SUMMARY:</div><div>==10556==     in use at exit: 5 bytes in 1 blocks</div><div>==10556==   total heap usage: 631 allocs, 630 frees, 25,236,667 bytes allocated</div><div>==10556== </div><div>==10556== 5 bytes in 1 blocks are definitely lost in loss record 1 of 1</div><div>==10556==    at 0x4A08B9D: realloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)</div><div>==10556==    by 0x4C75C68: utf8proc_map (dutf8proc.c:550)</div><div>==10556==    by 0x4C75D04: utf8proc_NFC (dutf8proc.c:566)</div><div>==10556==    by 0x4D3616B: ncmpii_NC_findattr (in /usr/local/lib/libnetcdf.so.11.0.0)</div><div>==10556==    by 0x4D391C9: ncmpii_put_att (in /usr/local/lib/libnetcdf.so.11.0.0)</div><div>==10556==    by 0x4D3969D: ncmpi_put_att_int (in /usr/local/lib/libnetcdf.so.11.0.0)</div><div>==10556==    by 0x4009A3: main (test_pnetcdf_leak.c:23)</div><div>==10556== </div><div>==10556== LEAK SUMMARY:</div><div>==10556==    definitely lost: 5 bytes in 1 blocks</div><div>==10556==    indirectly lost: 0 bytes in 0 blocks</div><div>==10556==      possibly lost: 0 bytes in 0 blocks</div><div>==10556==    still reachable: 0 bytes in 0 blocks</div><div>==10556==         suppressed: 0 bytes in 0 blocks</div><div>==10556== </div><div>==10556== For counts of detected and suppressed errors, rerun with: -v</div><div>==10556== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)</div><div>[ed@localhost unit]$ </div></div></div>