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

Fix many (but not all) memory leaks using gcc -fsanitize=address #1173

Merged
merged 2 commits into from
Nov 1, 2018

Conversation

DennisHeimbigner
Copy link
Collaborator

re: github issues
#1168
#1163
#1162

This PR partially fixes memory leaks in the netcdf-c library,
in the ncdump utility, and in some test cases.

The netcdf-c library now runs memory clean with the assumption
that the --disable-utilities option is used. The primary remaining
problem is ncgen. Once that is fixed, I believe the netcdf-c library
will run memory clean with no limitations.

Notes

  1. Memory checking was performed using gcc -fsanitize=address.
    Valgrind-based testing has yet to be performed.
  2. The pnetcdf, hdf4, and examples code has not been tested.

Misc. Non-leak changes

  1. Make tst_diskless2 only run when netcdf4 is enabled (issue 1162)
  2. Fix CmakeLists.txt to turn off logging if ENABLE_NETCDF_4 is OFF
  3. Isolated all my debug scripts into a single top-level directory
    called debug
  4. Fix some USE_NETCDF4 dependencies in nc_test and nc_test4 Makefile.am

    #1168
    #1163
    #1162

This PR partially fixes memory leaks in the netcdf-c library,
in the ncdump utility, and in some test cases.

The netcdf-c library now runs memory clean with the assumption
that the --disable-utilities option is used. The primary remaining
problem is ncgen. Once that is fixed, I believe the netcdf-c library
will run memory clean with no limitations.

Notes
-----------
1. Memory checking was performed using gcc -fsanitize=address.
   Valgrind-based testing has yet to be performed.
2. The pnetcdf, hdf4, and examples code has not been tested.

Misc. Non-leak changes
1. Make tst_diskless2 only run when netcdf4 is enabled (issue 1162)
2. Fix CmakeLists.txt to turn off logging if ENABLE_NETCDF_4 is OFF
3. Isolated all my debug scripts into a single top-level directory
   called debug
4. Fix some USE_NETCDF4 dependencies in nc_test and nc_test4 Makefile.am
@WardF
Copy link
Member

WardF commented Oct 31, 2018

This pull request fixes 1 alert when merging 245961d into 8d5e66e - view on LGTM.com

fixed alerts:

  • 1 for Function declared in block

Comment posted by LGTM.com

# Build test programs plus programs used in test scripts.
check_PROGRAMS = $(NC4_TESTS) renamegroup tst_empty_vlen_unlim
TESTS = $(NC4_TESTS)
if USE_NETCDF4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if USE_NETCDF4 is not needed. The nc_test4 directory will be skipped if netCDF-4 is not enabled, so there is no need to check USE_NETCDF4, it will always be true.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing out the redundancy; reviewing this now then will get the PR out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than kick off the whole CI chain by removing this redundancy, I'll note it for removal after the merge.

@WardF
Copy link
Member

WardF commented Oct 31, 2018

@DennisHeimbigner I'm seeing a failure, repeatable, in dap4_test/test_remote.sh. The failure details can be seen here:

@WardF
Copy link
Member

WardF commented Oct 31, 2018

  • Update: I'm only seeing that on OSX. So I will try to debug.

@WardF
Copy link
Member

WardF commented Oct 31, 2018

The issue is as follows on OSX; I'm not sure why diff -wBb works on Linux but not OSX.

The file is test_atomic_array_syn.dmp. In the 'baseline/` directory, the 'vo' variable appears as follows:

 vo =
  
    0XA2177AA7287C04FA8BB57BCDF76EC80F, 
    0X34FA472AA9404DD543143CADED303A75 ;

In the results_test_remote/ directory, the vo variable appears as follows:

 vo =
  0XA2177AA7287C04FA8BB57BCDF76EC80F, 0X34FA472AA9404DD543143CADED303A75 
;

Ignoring whitespace via diff on OSX doesn't appear to fix this issue, as it does on Linux.

@WardF
Copy link
Member

WardF commented Oct 31, 2018

Added the fix, baby-sitting the CI, will merge and update other PR's ASAP. New RC tomorrow.

@WardF
Copy link
Member

WardF commented Oct 31, 2018

This pull request fixes 1 alert when merging 5ad2410 into 8d5e66e - view on LGTM.com

fixed alerts:

  • 1 for Function declared in block

Comment posted by LGTM.com

@DennisHeimbigner
Copy link
Collaborator Author

ok.

@WardF
Copy link
Member

WardF commented Nov 1, 2018

Merging into release branch for the RC going out today; it will then make its way back into the master branch.

@WardF WardF merged commit 5ad2410 into master Nov 1, 2018
@DennisHeimbigner DennisHeimbigner deleted the leak1.dmh branch November 2, 2018 03:09
DennisHeimbigner added a commit that referenced this pull request Nov 15, 2018
This is a follow up to PR #1173

Sorry that it is so big, but leak suppression can be complex.

This PR fixes all remaining memory leaks -- as determined by
-fsanitize=address, and with the exceptions noted below.

Unfortunately. there remains a significant leak that I cannot
solve. It involves vlens, and it is unclear if the leak is
occurring in the netcdf-c library or the HDF5 library.

I have added a check_PROGRAM to the ncdump directory to show the
problem.  The program is called tst_vlen_demo.c To exercise it,
build the netcdf library with -fsanitize=address enabled. Then
go into ncdump and do a "make clean check".  This should build
tst_vlen_demo without actually executing it.  Then do the
command "./tst_vlen_demo" to see the output of the memory
checker.  Note the the lost malloc is deep in the HDF5 library
(in H5Tvlen.c).

I am temporarily working around this error in the following way.
1. I modified several test scripts to not execute known vlen tests
   that fail as described above.
2. Added an environment variable called NC_VLEN_NOTEST.
   If set, then those specific tests are suppressed.

This should mean that the --disable-utilities option to
./configure should not need to be set to get a memory leak clean
build.  This should allow for detection of any new leaks.

Note: I used an environment variable rather than a ./configure
option to control the vlen tests. This is because it is
temporary (I hope) and because it is a bit tricky for shell
scripts to access ./configure options.

Finally, as before, this only been tested with netcdf-4 and hdf5 support.
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

Successfully merging this pull request may close these issues.

3 participants