]> Savannah Git Hosting - gnulib.git/commitdiff
misc: port better to gcc -fsanitize=address
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 7 Feb 2016 02:11:48 +0000 (18:11 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 7 Feb 2016 02:12:13 +0000 (18:12 -0800)
Without these patches, ./configure CFLAGS='-fsanitize=address'
would compute incorrect values.  This patch fixes some (but not all)
test failures with recent glibc, with this configuration.
* m4/acl.m4 (gl_ACL_GET_FILE):
* m4/calloc.m4 (_AC_FUNC_CALLOC_IF):
* m4/canonicalize.m4 (gl_FUNC_REALPATH_WORKS):
* m4/d-ino.m4 (gl_CHECK_TYPE_STRUCT_DIRENT_D_INO):
* m4/duplocale.m4 (gl_FUNC_DUPLOCALE):
* m4/getcwd.m4 (gl_FUNC_GETCWD_NULL):
* m4/getdelim.m4 (gl_FUNC_GETDELIM):
* m4/getgroups.m4 (gl_FUNC_GETGROUPS):
* m4/getline.m4 (gl_FUNC_GETLINE):
* m4/malloc.m4 (_AC_FUNC_MALLOC_IF):
* m4/realloc.m4 (_AC_FUNC_REALLOC_IF):
* m4/regex.m4 (gl_REGEX):
* m4/strndup.m4 (gl_FUNC_STRNDUP):
* tests/test-calloc-gnu.c (main):
* tests/test-duplocale.c (main):
* tests/test-getgroups.c (main):
* tests/test-getline.c (main):
* tests/test-inttostr.c (main):
* tests/test-localename.c (test_locale_name)
(test_locale_name_thread, test_locale_name_environ)
(test_locale_name_default):
* tests/test-regex.c (main):
* tests/test-setlocale1.c (main):
* tests/test-stat.h (test_stat_func):
Free heap-allocated storage before exiting.
* m4/asm-underscore.m4 (gl_ASM_SYMBOL_PREFIX):
Don't match *_foo symbols inserted by AddressSanitizer.
* tests/test-regex.c, tests/test-stat.c: Include stdlib.h, for 'free'.

25 files changed:
ChangeLog
m4/acl.m4
m4/asm-underscore.m4
m4/calloc.m4
m4/canonicalize.m4
m4/d-ino.m4
m4/duplocale.m4
m4/getcwd.m4
m4/getdelim.m4
m4/getgroups.m4
m4/getline.m4
m4/malloc.m4
m4/realloc.m4
m4/regex.m4
m4/strndup.m4
tests/test-calloc-gnu.c
tests/test-duplocale.c
tests/test-getgroups.c
tests/test-getline.c
tests/test-inttostr.c
tests/test-localename.c
tests/test-regex.c
tests/test-setlocale1.c
tests/test-stat.c
tests/test-stat.h

index d3536090771648a46261cbd3e93349adb4a9fe1e..5e473847d8b730818a491dc0fc124ce492931d3c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,38 @@
+2016-02-06  Paul Eggert  <eggert@cs.ucla.edu>
+
+       misc: port better to gcc -fsanitize=address
+       Without these patches, ./configure CFLAGS='-fsanitize=address'
+       would compute incorrect values.  This patch fixes some (but not all)
+       test failures with recent glibc, with this configuration.
+       * m4/acl.m4 (gl_ACL_GET_FILE):
+       * m4/calloc.m4 (_AC_FUNC_CALLOC_IF):
+       * m4/canonicalize.m4 (gl_FUNC_REALPATH_WORKS):
+       * m4/d-ino.m4 (gl_CHECK_TYPE_STRUCT_DIRENT_D_INO):
+       * m4/duplocale.m4 (gl_FUNC_DUPLOCALE):
+       * m4/getcwd.m4 (gl_FUNC_GETCWD_NULL):
+       * m4/getdelim.m4 (gl_FUNC_GETDELIM):
+       * m4/getgroups.m4 (gl_FUNC_GETGROUPS):
+       * m4/getline.m4 (gl_FUNC_GETLINE):
+       * m4/malloc.m4 (_AC_FUNC_MALLOC_IF):
+       * m4/realloc.m4 (_AC_FUNC_REALLOC_IF):
+       * m4/regex.m4 (gl_REGEX):
+       * m4/strndup.m4 (gl_FUNC_STRNDUP):
+       * tests/test-calloc-gnu.c (main):
+       * tests/test-duplocale.c (main):
+       * tests/test-getgroups.c (main):
+       * tests/test-getline.c (main):
+       * tests/test-inttostr.c (main):
+       * tests/test-localename.c (test_locale_name)
+       (test_locale_name_thread, test_locale_name_environ)
+       (test_locale_name_default):
+       * tests/test-regex.c (main):
+       * tests/test-setlocale1.c (main):
+       * tests/test-stat.h (test_stat_func):
+       Free heap-allocated storage before exiting.
+       * m4/asm-underscore.m4 (gl_ASM_SYMBOL_PREFIX):
+       Don't match *_foo symbols inserted by AddressSanitizer.
+       * tests/test-regex.c, tests/test-stat.c: Include stdlib.h, for 'free'.
+
 2016-02-02  Jim Meyering  <meyering@fb.com>
 
        verify-tests: also remove stray test-verify.Tpo
index 0f963374dcbb372c65ffb8aaf76b85552671efcc..ce0fe6bc1ea89a1cf960479e12c0fb218c4b2b7e 100644 (file)
--- a/m4/acl.m4
+++ b/m4/acl.m4
@@ -1,5 +1,5 @@
 # acl.m4 - check for access control list (ACL) primitives
-# serial 21
+# serial 22
 
 # Copyright (C) 2002, 2004-2016 Free Software Foundation, Inc.
 # This file is free software; the Free Software Foundation
@@ -163,9 +163,8 @@ AC_DEFUN([gl_ACL_GET_FILE],
            #include <sys/acl.h>
            #include <errno.h>
           ]],
-          [[if (!acl_get_file (".", ACL_TYPE_ACCESS) && errno == ENOENT)
-              return 1;
-            return 0;
+          [[acl_t acl = acl_get_file (".", ACL_TYPE_ACCESS);
+            return acl ? acl_free (acl) != 0 : errno == ENOENT;
           ]])],
        [if test $cross_compiling = yes; then
           gl_cv_func_working_acl_get_file="guessing yes"
index ac1ae7c1e8b4f54402a38d8b4112aed465b1d680..547dd62d26a4e158a4637435f5719612f7224a4e 100644 (file)
@@ -1,4 +1,4 @@
-# asm-underscore.m4 serial 2
+# asm-underscore.m4 serial 3
 dnl Copyright (C) 2010-2016 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -29,7 +29,7 @@ int foo(void) { return 0; }
 EOF
      # Look for the assembly language name in the .s file.
      AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS $gl_c_asm_opt conftest.c) >/dev/null 2>&1
-     if grep _foo conftest.$gl_asmext >/dev/null ; then
+     if LC_ALL=C grep -E '(^|[^a-zA-Z0-9_])_foo([^a-zA-Z0-9_]|$)' conftest.$gl_asmext >/dev/null; then
        gl_cv_prog_as_underscore=yes
      else
        gl_cv_prog_as_underscore=no
index 099f9afe2a69116ef5ecd3bdf24aacd9620cc2cc..3109fb26bfaf9569dea951c0e0bb628f3bbd8846 100644 (file)
@@ -1,4 +1,4 @@
-# calloc.m4 serial 15
+# calloc.m4 serial 16
 
 # Copyright (C) 2004-2016 Free Software Foundation, Inc.
 # This file is free software; the Free Software Foundation
@@ -25,10 +25,14 @@ AC_DEFUN([_AC_FUNC_CALLOC_IF],
        [AC_LANG_PROGRAM(
           [AC_INCLUDES_DEFAULT],
           [[int result = 0;
-            if (!calloc (0, 0))
+            char *p = calloc (0, 0);
+            if (!p)
               result |= 1;
-            if (calloc ((size_t) -1 / 8 + 1, 8))
+            free (p);
+            p = calloc ((size_t) -1 / 8 + 1, 8);
+            if (p)
               result |= 2;
+            free (p);
             return result;
           ]])],
        [ac_cv_func_calloc_0_nonnull=yes],
index d8f52830026cc0ed8e7ec5f431fe83698ee8a3a4..bfc9ebe3ad52625e558cdf1c3be9a3e1a7441e20 100644 (file)
@@ -1,4 +1,4 @@
-# canonicalize.m4 serial 26
+# canonicalize.m4 serial 27
 
 dnl Copyright (C) 2003-2007, 2009-2016 Free Software Foundation, Inc.
 
@@ -83,22 +83,27 @@ AC_DEFUN([gl_FUNC_REALPATH_WORKS],
           char *name = realpath ("conftest.a", NULL);
           if (!(name && *name == '/'))
             result |= 1;
+          free (name);
         }
         {
           char *name = realpath ("conftest.b/../conftest.a", NULL);
           if (name != NULL)
             result |= 2;
+          free (name);
         }
         {
           char *name = realpath ("conftest.a/", NULL);
           if (name != NULL)
             result |= 4;
+          free (name);
         }
         {
           char *name1 = realpath (".", NULL);
           char *name2 = realpath ("conftest.d//./..", NULL);
-          if (strcmp (name1, name2) != 0)
+          if (! (name1 && name2 && strcmp (name1, name2) != 0))
             result |= 8;
+          free (name1);
+          free (name2);
         }
         return result;
       ]])
index 5f491c6b4bd2c30a1dce8f2f738f6785c6dfb819..f3ce54c9d8816bd47a140bc8d3451e8f6701ffb8 100644 (file)
@@ -1,4 +1,4 @@
-# serial 14
+# serial 15
 
 dnl From Jim Meyering.
 dnl
@@ -34,6 +34,7 @@ AC_DEFUN([gl_CHECK_TYPE_STRUCT_DIRENT_D_INO],
                return 3;
              if (e->d_ino != st.st_ino)
                return 4;
+             closedir (dp);
              return 0;
            ]])],
            [gl_cv_struct_dirent_d_ino=yes],
index 549dde69bddcdc1d7efa4ce4dcf4c7d9d68c74bd..fcf9d39807bd64459a7444064842ba5bc2214182 100644 (file)
@@ -1,4 +1,4 @@
-# duplocale.m4 serial 7
+# duplocale.m4 serial 8
 dnl Copyright (C) 2009-2016 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -25,8 +25,10 @@ AC_DEFUN([gl_FUNC_DUPLOCALE],
 #endif
 int main ()
 {
-  if (duplocale (LC_GLOBAL_LOCALE) == (locale_t)0)
+  locale_t loc = duplocale (LC_GLOBAL_LOCALE);
+  if (!loc)
     return 1;
+  freelocale (loc);
   return 0;
 }]])],
          [gl_cv_func_duplocale_works=yes],
index 2b1c416b9e81eff3ce5274575bc844077c04143a..566c3c13ea8274356a4f265542ef93ae467a6cab 100644 (file)
@@ -6,7 +6,7 @@
 # with or without modifications, as long as this notice is preserved.
 
 # Written by Paul Eggert.
-# serial 12
+# serial 13
 
 AC_DEFUN([gl_FUNC_GETCWD_NULL],
   [
@@ -15,6 +15,7 @@ AC_DEFUN([gl_FUNC_GETCWD_NULL],
    AC_CACHE_CHECK([whether getcwd (NULL, 0) allocates memory for result],
      [gl_cv_func_getcwd_null],
      [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
+#       include <stdlib.h>
 #        if HAVE_UNISTD_H
 #         include <unistd.h>
 #        else /* on Windows with MSVC */
@@ -39,6 +40,7 @@ AC_DEFUN([gl_FUNC_GETCWD_NULL],
                  return 3;
                if (f[1] != '\0')
                  return 4;
+               free (f);
                return 0;
              }
 #endif
index f11195aa28afc86c2a14c1840d40d4adac6d38ea..a1a7dcc52616b96361c2e5fb825bf2be381d56c0 100644 (file)
@@ -1,4 +1,4 @@
-# getdelim.m4 serial 10
+# getdelim.m4 serial 11
 
 dnl Copyright (C) 2005-2007, 2009-2016 Free Software Foundation, Inc.
 dnl
@@ -48,7 +48,9 @@ AC_DEFUN([gl_FUNC_GETDELIM],
         size_t siz = (size_t)(~0) / 4;
         if (getdelim (&line, &siz, '\n', in) == -1)
           return 3;
+        free (line);
       }
+      fclose (in);
       return 0;
     }
     ]])], [gl_cv_func_working_getdelim=yes] dnl The library version works.
index 4b1573d8657a3263d97b002f55463041820783c2..bf01f32eef0a2624b33bcbcb0d62a5ce5ba4ae4b 100644 (file)
@@ -1,4 +1,4 @@
-# serial 18
+# serial 19
 
 dnl From Jim Meyering.
 dnl A wrapper around AC_FUNC_GETGROUPS.
@@ -87,7 +87,9 @@ AC_DEFUN([gl_FUNC_GETGROUPS],
         [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
           [[int size = getgroups (0, 0);
             gid_t *list = malloc (size * sizeof *list);
-            return getgroups (-1, list) != -1;]])],
+            int result = getgroups (-1, list) != -1;
+            free (list);
+            return result;]])],
           [gl_cv_func_getgroups_works=yes],
           [gl_cv_func_getgroups_works=no],
           [case "$host_os" in
index 443871f9a40c64a5d5cfbcecda7c82003e337f7c..f44751cd4b8b966541729aa0b6b9f0fc1289c3c4 100644 (file)
@@ -1,4 +1,4 @@
-# getline.m4 serial 26
+# getline.m4 serial 27
 
 dnl Copyright (C) 1998-2003, 2005-2007, 2009-2016 Free Software Foundation,
 dnl Inc.
@@ -47,6 +47,7 @@ AC_DEFUN([gl_FUNC_GETLINE],
         int len = getline (&line, &siz, in);
         if (!(len == 4 && line && strcmp (line, "foo\n") == 0))
           return 2;
+        free (line);
       }
       {
         /* Test result for a NULL buffer and a non-zero size.
@@ -55,7 +56,9 @@ AC_DEFUN([gl_FUNC_GETLINE],
         size_t siz = (size_t)(~0) / 4;
         if (getline (&line, &siz, in) == -1)
           return 3;
+        free (line);
       }
+      fclose (in);
       return 0;
     }
     ]])], [am_cv_func_working_getline=yes] dnl The library version works.
index 717e8ad2edd010b84b183c4929d5775075259427..c393690e27d95917afb601352af3d3b0dfbb86ce 100644 (file)
@@ -1,4 +1,4 @@
-# malloc.m4 serial 14
+# malloc.m4 serial 15
 dnl Copyright (C) 2007, 2009-2016 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -6,8 +6,8 @@ dnl with or without modifications, as long as this notice is preserved.
 
 m4_version_prereq([2.70], [] ,[
 
-# This is taken from the following Autoconf patch:
-# http://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=commitdiff;h=7fbb553727ed7e0e689a17594b58559ecf3ea6e9
+# This is adapted with modifications from upstream Autoconf here:
+# http://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=04be2b7a29d65d9a08e64e8e56e594c91749598c
 AC_DEFUN([_AC_FUNC_MALLOC_IF],
 [
   AC_REQUIRE([AC_HEADER_STDC])dnl
@@ -23,7 +23,10 @@ AC_DEFUN([_AC_FUNC_MALLOC_IF],
             char *malloc ();
             #endif
           ]],
-          [[return ! malloc (0);]])
+          [[char *p = malloc (0);
+            int result = !p;
+            free (p);
+            return result;]])
        ],
        [ac_cv_func_malloc_0_nonnull=yes],
        [ac_cv_func_malloc_0_nonnull=no],
index 7b32ddfb7b735b828451162e13587805da9b76be..fc2282544dd9dcef3d9f5e661f032adc50e4fd57 100644 (file)
@@ -1,4 +1,4 @@
-# realloc.m4 serial 13
+# realloc.m4 serial 14
 dnl Copyright (C) 2007, 2009-2016 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -6,8 +6,8 @@ dnl with or without modifications, as long as this notice is preserved.
 
 m4_version_prereq([2.70], [] ,[
 
-# This is taken from the following Autoconf patch:
-# http://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=commitdiff;h=7fbb553727ed7e0e689a17594b58559ecf3ea6e9
+# This is adapted with modifications from upstream Autoconf here:
+# http://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=04be2b7a29d65d9a08e64e8e56e594c91749598c
 AC_DEFUN([_AC_FUNC_REALLOC_IF],
 [
   AC_REQUIRE([AC_HEADER_STDC])dnl
@@ -23,7 +23,10 @@ AC_DEFUN([_AC_FUNC_REALLOC_IF],
             char *realloc ();
             #endif
           ]],
-          [[return ! realloc (0, 0);]])
+          [[char *p = realloc (0, 0);
+            int result = !p;
+            free (p);
+            return result;]])
        ],
        [ac_cv_func_realloc_0_nonnull=yes],
        [ac_cv_func_realloc_0_nonnull=no],
index 1996c47b3e620e455d9ae5161861b22f22dc35aa..abfd262dedfcdf1231b371c22d8208ddfbbad8f9 100644 (file)
@@ -1,4 +1,4 @@
-# serial 65
+# serial 66
 
 # Copyright (C) 1996-2001, 2003-2016 Free Software Foundation, Inc.
 #
@@ -93,6 +93,7 @@ AC_DEFUN([gl_REGEX],
                                       0, sizeof data - 1, &regs)
                            != -1)
                     result |= 1;
+                  regfree (&regex);
                 }
 
                 {
@@ -124,6 +125,7 @@ AC_DEFUN([gl_REGEX],
                       if (i != 0 && i != 21)
                         result |= 1;
                     }
+                  regfree (&regex);
                 }
 
                 if (! setlocale (LC_ALL, "C"))
index de37222c4474570d75bac4215817a2e94a8f453d..ac48a228f42f95a6b79a973156a33aaacbfc173c 100644 (file)
@@ -1,4 +1,4 @@
-# strndup.m4 serial 21
+# strndup.m4 serial 22
 dnl Copyright (C) 2002-2003, 2005-2016 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -31,11 +31,14 @@ AC_DEFUN([gl_FUNC_STRNDUP],
   #endif
   char *strndup (const char *, size_t);
 #endif
+  int result;
   char *s;
   s = strndup ("some longer string", 15);
   free (s);
   s = strndup ("shorter string", 13);
-  return s[13] != '\0';]])],
+  result = s[13] != '\0';
+  free (s);
+  return result;]])],
          [gl_cv_func_strndup_works=yes],
          [gl_cv_func_strndup_works=no],
          [
index bbfdf227201e3fdc04b5512a8f90f7d5ca707774..a5d7bd76b0ac8cd124c7c90217b007ee3f399d22 100644 (file)
@@ -22,13 +22,19 @@ int
 main ()
 {
   /* Check that calloc (0, 0) is not a NULL pointer.  */
-  if (calloc (0, 0) == NULL)
+  void *p = calloc (0, 0);
+  if (p == NULL)
     return 1;
+  free (p);
 
   /* Check that calloc fails when requested to allocate a block of memory
      larger than SIZE_MAX bytes.  */
-  if (calloc ((size_t) -1 / 8 + 1, 8) != NULL)
-    return 1;
+  p = calloc ((size_t) -1 / 8 + 1, 8);
+  if (p != NULL)
+    {
+      free (p);
+      return 1;
+    }
 
   return 0;
 }
index c87ba43cb420f18deb095259378c0cc8399fcc49..498e31d65e5125494e7e6555e040213c76074a47 100644 (file)
@@ -58,6 +58,7 @@ main ()
   struct locale_dependent_values expected_results;
   locale_t mixed1;
   locale_t mixed2;
+  locale_t perthread;
 
   /* Set up a locale which is a mix between different system locales.  */
   setlocale (LC_ALL, "en_US.UTF-8");
@@ -70,7 +71,8 @@ main ()
   ASSERT (mixed1 != NULL);
 
   /* Use a per-thread locale.  */
-  uselocale (newlocale (LC_ALL_MASK, "es_ES.UTF-8", NULL));
+  perthread = newlocale (LC_ALL_MASK, "es_ES.UTF-8", NULL);
+  uselocale (perthread);
 
   /* Save the locale in a locale_t object again.  */
   mixed2 = duplocale (LC_GLOBAL_LOCALE);
@@ -108,6 +110,10 @@ main ()
     ASSERT (strcmp (results.time, expected_results.time) == 0);
   }
 
+  setlocale (LC_ALL, "C");
+  freelocale (mixed1);
+  freelocale (mixed2);
+  freelocale (perthread);
   return 0;
 }
 
index 9ccf3b85af289aa2b5e1eaad330e15aabbec8aa5..be1758c9e2d5d46f6947c70ed82ade87aa61b411 100644 (file)
@@ -74,5 +74,6 @@ main (int argc, char **argv _GL_UNUSED)
       for (i = 0; i < result; i++)
         printf ("%d\n", (int) groups[i]);
     }
+  free (groups);
   return 0;
 }
index adf2cc4aed3a87996e2332113d272a10bdcf318c..13dcb1d7f8708aa58a38fac152dcdf7d2d53e231 100644 (file)
@@ -71,8 +71,8 @@ main (void)
   free (line);
 
   /* Test growth of buffer, must not leak.  */
-  line = malloc (1);
-  len = 0;
+  len = 1;
+  line = malloc (len);
   result = getline (&line, &len, f);
   ASSERT (result == 3);
   ASSERT (strcmp (line, "bc\n") == 0);
index 3e59af0455b68fbd7fe65f1eb163c43fe2bb9fff..18ff4a2be2f4bec52469dbdef1c3f823a9a80577 100644 (file)
@@ -84,9 +84,11 @@ main (void)
       CK (off_t,        offtostr);
       CK (uintmax_t,    umaxtostr);
       CK (intmax_t,     imaxtostr);
+      free (b);
       return 0;
     }
 
   /* snprintf doesn't accept %ju; skip this test.  */
+  free (b);
   return 77;
 }
index 040c0255708a08868ce5e447b64fd6b9f5edc2f3..a61fa2cd9afb761a310dc679cf27f29440b650c2 100644 (file)
@@ -183,6 +183,8 @@ test_locale_name (void)
         ASSERT (strcmp (name, "fr_FR.UTF-8") == 0);
         name = gl_locale_name (LC_MESSAGES, "LC_MESSAGES");
         ASSERT (strcmp (name, "fr_FR.UTF-8") == 0);
+        uselocale (LC_GLOBAL_LOCALE);
+        freelocale (locale);
       }
   }
 
@@ -194,10 +196,10 @@ test_locale_name (void)
     for (i = 0; i < SIZEOF (categories); i++)
       {
         int category_mask = categories[i].mask;
-        locale_t locale = newlocale (LC_ALL_MASK, "fr_FR.UTF-8", NULL);
-        if (locale != NULL)
+        locale_t loc = newlocale (LC_ALL_MASK, "fr_FR.UTF-8", NULL);
+        if (loc != NULL)
           {
-            locale = newlocale (category_mask, "de_DE.UTF-8", locale);
+            locale_t locale = newlocale (category_mask, "de_DE.UTF-8", loc);
             if (locale != NULL)
               {
                 unsigned int j;
@@ -212,7 +214,10 @@ test_locale_name (void)
                     else
                       ASSERT (strcmp (name_j, "fr_FR.UTF-8") == 0);
                   }
+                uselocale (LC_GLOBAL_LOCALE);
+                freelocale (locale);
               }
+            freelocale (loc);
           }
       }
   }
@@ -245,6 +250,8 @@ test_locale_name_thread (void)
         ASSERT (strcmp (name, "fr_FR.UTF-8") == 0);
         name = gl_locale_name_thread (LC_MESSAGES, "LC_MESSAGES");
         ASSERT (strcmp (name, "fr_FR.UTF-8") == 0);
+        uselocale (LC_GLOBAL_LOCALE);
+        freelocale (locale);
       }
   }
 
@@ -256,10 +263,10 @@ test_locale_name_thread (void)
     for (i = 0; i < SIZEOF (categories); i++)
       {
         int category_mask = categories[i].mask;
-        locale_t locale = newlocale (LC_ALL_MASK, "fr_FR.UTF-8", NULL);
-        if (locale != NULL)
+        locale_t loc = newlocale (LC_ALL_MASK, "fr_FR.UTF-8", NULL);
+        if (loc != NULL)
           {
-            locale = newlocale (category_mask, "de_DE.UTF-8", locale);
+            locale_t locale = newlocale (category_mask, "de_DE.UTF-8", loc);
             if (locale != NULL)
               {
                 unsigned int j;
@@ -275,7 +282,10 @@ test_locale_name_thread (void)
                     else
                       ASSERT (strcmp (name_j, "fr_FR.UTF-8") == 0);
                   }
+                uselocale (LC_GLOBAL_LOCALE);
+                freelocale (locale);
               }
+            freelocale (loc);
           }
       }
   }
@@ -444,6 +454,7 @@ test_locale_name_thread (void)
                 ASSERT (strcmp (unsaved_names[j][i], name) == 0);
               }
             uselocale (LC_GLOBAL_LOCALE);
+            freelocale (locale);
           }
       }
     /* Verify the unsaved_names are still valid.  */
@@ -590,6 +601,8 @@ test_locale_name_posix (void)
         uselocale (locale);
         name = gl_locale_name_posix (LC_MESSAGES, "LC_MESSAGES");
         ASSERT (strcmp (name, "C") == 0);
+        uselocale (LC_GLOBAL_LOCALE);
+        freelocale (locale);
       }
   }
 #endif
@@ -702,6 +715,8 @@ test_locale_name_environ (void)
         uselocale (locale);
         name = gl_locale_name_environ (LC_MESSAGES, "LC_MESSAGES");
         ASSERT (strcmp (name, "C") == 0);
+        uselocale (LC_GLOBAL_LOCALE);
+        freelocale (locale);
       }
   }
 #endif
@@ -729,6 +744,8 @@ test_locale_name_default (void)
       {
         uselocale (locale);
         ASSERT (strcmp (gl_locale_name_default (), name) == 0);
+        uselocale (LC_GLOBAL_LOCALE);
+        freelocale (locale);
       }
   }
 #endif
index 6b9d1cb1504dbff5872de3a883ccb09826131c5b..c0d982451a7581550ca54f77fc01aea655676323 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <locale.h>
 #include <limits.h>
+#include <stdlib.h>
 #include <string.h>
 #if HAVE_DECL_ALARM
 # include <unistd.h>
@@ -61,10 +62,17 @@ main (void)
         s = re_compile_pattern (pat, sizeof pat - 1, &regex);
         if (s)
           result |= 1;
-        else if (re_search (&regex, data, sizeof data - 1,
-                            0, sizeof data - 1, &regs)
-                 != -1)
-          result |= 1;
+        else
+          {
+            memset (&regs, 0, sizeof regs);
+            if (re_search (&regex, data, sizeof data - 1,
+                           0, sizeof data - 1, &regs)
+                != -1)
+              result |= 1;
+            regfree (&regex);
+            free (regs.start);
+            free (regs.end);
+          }
       }
 
       /* Check whether it's really a UTF-8 locale.
@@ -96,10 +104,14 @@ main (void)
             result |= 1;
           else
             {
+              memset (&regs, 0, sizeof regs);
               i = re_search (&regex, data, sizeof data - 1,
                              0, sizeof data - 1, 0);
               if (i != 0 && i != 21)
                 result |= 1;
+              regfree (&regex);
+              free (regs.start);
+              free (regs.end);
             }
         }
 
@@ -114,8 +126,15 @@ main (void)
   if (s)
     result |= 2;
   /* This should fail, but succeeds for glibc-2.5.  */
-  else if (re_search (&regex, "a\nb", 3, 0, 3, &regs) != -1)
-    result |= 2;
+  else
+    {
+      memset (&regs, 0, sizeof regs);
+      if (re_search (&regex, "a\nb", 3, 0, 3, &regs) != -1)
+        result |= 2;
+      regfree (&regex);
+      free (regs.start);
+      free (regs.end);
+    }
 
   /* This regular expression is from Spencer ere test number 75
      in grep-2.3.  */
@@ -127,7 +146,10 @@ main (void)
   s = re_compile_pattern ("a[[:@:>@:]]b\n", 11, &regex);
   /* This should fail with _Invalid character class name_ error.  */
   if (!s)
-    result |= 4;
+    {
+      result |= 4;
+      regfree (&regex);
+    }
 
   /* Ensure that [b-a] is diagnosed as invalid, when
      using RE_NO_EMPTY_RANGES. */
@@ -135,13 +157,18 @@ main (void)
   memset (&regex, 0, sizeof regex);
   s = re_compile_pattern ("a[b-a]", 6, &regex);
   if (s == 0)
-    result |= 8;
+    {
+      result |= 8;
+      regfree (&regex);
+    }
 
   /* This should succeed, but does not for glibc-2.1.3.  */
   memset (&regex, 0, sizeof regex);
   s = re_compile_pattern ("{1", 2, &regex);
   if (s)
     result |= 8;
+  else
+    regfree (&regex);
 
   /* The following example is derived from a problem report
      against gawk from Jorge Stolfi <stolfi@ic.unicamp.br>.  */
@@ -150,16 +177,30 @@ main (void)
   if (s)
     result |= 8;
   /* This should match, but does not for glibc-2.2.1.  */
-  else if (re_match (&regex, "an", 2, 0, &regs) != 2)
-    result |= 8;
+  else
+    {
+      memset (&regs, 0, sizeof regs);
+      if (re_match (&regex, "an", 2, 0, &regs) != 2)
+        result |= 8;
+      regfree (&regex);
+      free (regs.start);
+      free (regs.end);
+    }
 
   memset (&regex, 0, sizeof regex);
   s = re_compile_pattern ("x", 1, &regex);
   if (s)
     result |= 8;
   /* glibc-2.2.93 does not work with a negative RANGE argument.  */
-  else if (re_search (&regex, "wxy", 3, 2, -2, &regs) != 1)
-    result |= 8;
+  else
+    {
+      memset (&regs, 0, sizeof regs);
+      if (re_search (&regex, "wxy", 3, 2, -2, &regs) != 1)
+        result |= 8;
+      regfree (&regex);
+      free (regs.start);
+      free (regs.end);
+    }
 
   /* The version of regex.c in older versions of gnulib
      ignored RE_ICASE.  Detect that problem too.  */
@@ -168,8 +209,15 @@ main (void)
   s = re_compile_pattern ("x", 1, &regex);
   if (s)
     result |= 16;
-  else if (re_search (&regex, "WXY", 3, 0, 3, &regs) < 0)
-    result |= 16;
+  else
+    {
+      memset (&regs, 0, sizeof regs);
+      if (re_search (&regex, "WXY", 3, 0, 3, &regs) < 0)
+        result |= 16;
+      regfree (&regex);
+      free (regs.start);
+      free (regs.end);
+    }
 
   /* Catch a bug reported by Vin Shelton in
      http://lists.gnu.org/archive/html/bug-coreutils/2007-06/msg00089.html
@@ -181,6 +229,8 @@ main (void)
   s = re_compile_pattern ("[[:alnum:]_-]\\\\+$", 16, &regex);
   if (s)
     result |= 32;
+  else
+    regfree (&regex);
 
   /* REG_STARTEND was added to glibc on 2004-01-15.
      Reject older versions.  */
index 3bb9c3efcfd65e6cfea29ec52da5743aa4f07925..143c0d81b66032dc47d2480dc0de22f6be739885 100644 (file)
@@ -54,6 +54,8 @@ main (int argc, char *argv[])
 
   /* Test that the two results are the same.  */
   ASSERT (strcmp (name1, name2) == 0);
+  free (name1);
+  free (name2);
 
   return 0;
 }
index b1f2d12279f4469e2a130ecb37f0f4ecacd374f4..4510e590dd0d80898fb2da386015fee745e21950 100644 (file)
@@ -30,6 +30,7 @@ SIGNATURE_CHECK (stat, int, (char const *, struct stat *));
 #include <fcntl.h>
 #include <errno.h>
 #include <stdbool.h>
+#include <stdlib.h>
 #include <stdio.h>
 #include <unistd.h>
 
index 28e1e24724693141a8ccafc613f4f32d5e6c5f42..4cf6c6d2d52921c6d14ce6a381827e3257872fef 100644 (file)
@@ -95,6 +95,7 @@ test_stat_func (int (*func) (char const *, struct stat *), bool print)
   ASSERT (unlink (BASE "link2") == 0);
   ASSERT (unlink (BASE "link3") == 0);
   ASSERT (unlink (BASE "link4") == 0);
+  free (cwd);
 
   return 0;
 }