From 19a23ce7c07fcac4c969dfec254ba02e59975e96 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sun, 20 Nov 2016 08:33:38 -0800 Subject: [PATCH] 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 --- ChangeLog | 11 +++++++++++ tests/test-exclude.c | 2 ++ tests/test-malloc-gnu.c | 4 +++- tests/test-realloc-gnu.c | 4 +++- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 38ece9d..88139c3 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 7a13faf..e03a868 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 5a7b832..8f46a20 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 6693834..1666d77 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; } -- 2.9.3