From: Jim Meyering Date: Sun, 20 Nov 2016 16:33:38 +0000 (-0800) Subject: fix test driver leaks: exclude, malloc, realloc X-Git-Tag: v1.0~6540 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=19a23ce7c07fcac4c969dfec254ba02e59975e96;p=gnulib.git fix test driver leaks: exclude, malloc, realloc * tests/test-exclude.c (main): Fix trivial leak. * tests/test-malloc-gnu.c (main): Likewise. * tests/test-realloc-gnu.c (main): Likewise. With these changes, grep's tests are now leak free. I.e., running them with ASAN elicits no failure: make CFLAGS='-O0 -ggdb3' AM_CFLAGS=-fsanitize=address \ AM_LDFLAGS='-fsanitize=address -static-libasan' check --- diff --git a/ChangeLog b/ChangeLog index 38ece9d7a6..88139c35d0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2016-11-20 Jim Meyering + + fix test driver leaks: exclude, malloc, realloc + * tests/test-exclude.c (main): Fix trivial leak. + * tests/test-malloc-gnu.c (main): Likewise. + * tests/test-realloc-gnu.c (main): Likewise. + With these changes, grep's tests are now leak free. + I.e., running them with ASAN elicits no failure: + make CFLAGS='-O0 -ggdb3' AM_CFLAGS=-fsanitize=address \ + AM_LDFLAGS='-fsanitize=address -static-libasan' check + 2016-11-11 Bruno Haible libunistring: Relicense under dual "LGPLv3+ or GPLv2" license. diff --git a/tests/test-exclude.c b/tests/test-exclude.c index 7a13faf865..e03a8687c3 100644 --- a/tests/test-exclude.c +++ b/tests/test-exclude.c @@ -122,5 +122,7 @@ main (int argc, char **argv) printf ("%s: %d\n", word, excluded_file_name (exclude, word)); } + + free_exclude (exclude); return 0; } diff --git a/tests/test-malloc-gnu.c b/tests/test-malloc-gnu.c index 5a7b832ee6..8f46a20752 100644 --- a/tests/test-malloc-gnu.c +++ b/tests/test-malloc-gnu.c @@ -22,8 +22,10 @@ int main () { /* Check that malloc (0) is not a NULL pointer. */ - if (malloc (0) == NULL) + char *p = malloc (0); + if (p == NULL) return 1; + free (p); return 0; } diff --git a/tests/test-realloc-gnu.c b/tests/test-realloc-gnu.c index 6693834af4..1666d772ea 100644 --- a/tests/test-realloc-gnu.c +++ b/tests/test-realloc-gnu.c @@ -22,8 +22,10 @@ int main () { /* Check that realloc (NULL, 0) is not a NULL pointer. */ - if (realloc (NULL, 0) == NULL) + char *p = realloc (NULL, 0); + if (p == NULL) return 1; + free (p); return 0; }