]> Savannah Git Hosting - gnulib.git/commitdiff
fix test driver leaks: exclude, malloc, realloc
authorJim Meyering <meyering@fb.com>
Sun, 20 Nov 2016 16:33:38 +0000 (08:33 -0800)
committerJim Meyering <meyering@fb.com>
Sun, 20 Nov 2016 16:33:38 +0000 (08:33 -0800)
* 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
tests/test-exclude.c
tests/test-malloc-gnu.c
tests/test-realloc-gnu.c

index 38ece9d7a6da3ef2373c413fe393fb56a86bbe21..88139c35d099b6f3b9d3b7e4b19f561ed65aa056 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2016-11-20  Jim Meyering  <meyering@fb.com>
+
+       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  <bruno@clisp.org>
 
        libunistring: Relicense under dual "LGPLv3+ or GPLv2" license.
index 7a13faf86581e4b5e076cb709ab054ddbe79d5b9..e03a8687c3aa4ddd32e3cd3255c63c4ecf4ed1c3 100644 (file)
@@ -122,5 +122,7 @@ main (int argc, char **argv)
 
       printf ("%s: %d\n", word, excluded_file_name (exclude, word));
     }
+
+  free_exclude (exclude);
   return 0;
 }
index 5a7b832ee6710090e6a845241654a0e4c2de04ab..8f46a20752aff26b80a0244c1202e82c55845db1 100644 (file)
@@ -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;
 }
index 6693834af4bda62d50916d1780640d04c5e7f0e8..1666d772ead53a281f86152ad9024cc4f6a0be29 100644 (file)
@@ -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;
 }