]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Fix memory leak in fnmatch
authorAndreas Schwab <schwab@redhat.com>
Fri, 12 Nov 2010 08:51:28 +0000 (03:51 -0500)
committerUlrich Drepper <drepper@gmail.com>
Fri, 12 Nov 2010 08:51:28 +0000 (03:51 -0500)
ChangeLog
posix/Makefile
posix/fnmatch_loop.c
posix/tst-fnmatch.c

index 5a7d9d2bed307098e008f6e9988407db060b7fa4..7fc8af25f935d4b63afb5193b2b0a7265e8c2bdd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2010-11-11  Andreas Schwab  <schwab@redhat.com>
+
+       * posix/fnmatch_loop.c (NEW_PATTERN): Fix use of alloca.
+       * posix/Makefile (tests): Add $(objpfx)tst-fnmatch-mem.
+       (tst-fnmatch-ENV): Set MALLOC_TRACE.
+       ($(objpfx)tst-fnmatch-mem): New rule.
+       (generated): Add tst-fnmatch-mem and tst-fnmatch.mtrace.
+       * posix/tst-fnmatch.c (main): Call mtrace.
+
 2010-11-11  H.J. Lu  <hongjiu.lu@intel.com>
 
        * sysdeps/x86_64/multiarch/init-arch.c (__init_cpu_features):
index 356896f7cc6f21ac3ad7359dafc91107dee01a34..373e50b0a9bbc2f7c1b8233c1db17d2509d64dd9 100644 (file)
@@ -115,7 +115,8 @@ generated := $(addprefix wordexp-test-result, 1 2 3 4 5 6 7 8 9 10) \
             tst-rxspencer-mem tst-rxspencer.mtrace tst-getconf.out \
             tst-pcre-mem tst-pcre.mtrace tst-boost-mem tst-boost.mtrace \
             bug-ga2.mtrace bug-ga2-mem bug-glob2.mtrace bug-glob2-mem \
-            tst-vfork3-mem tst-vfork3.mtrace getconf.speclist
+            tst-vfork3-mem tst-vfork3.mtrace getconf.speclist \
+            tst-fnmatch-mem tst-fnmatch.mtrace
 
 include ../Rules
 
@@ -235,7 +236,7 @@ ifeq (no,$(cross-compiling))
 tests: $(objpfx)bug-regex2-mem $(objpfx)bug-regex14-mem \
   $(objpfx)bug-regex21-mem $(objpfx)bug-regex31-mem $(objpfx)tst-rxspencer-mem\
   $(objpfx)tst-pcre-mem $(objpfx)tst-boost-mem $(objpfx)tst-getconf.out \
-  $(objpfx)bug-glob2-mem $(objpfx)tst-vfork3-mem
+  $(objpfx)bug-glob2-mem $(objpfx)tst-vfork3-mem $(objpfx)tst-fnmatch-mem
 xtests: $(objpfx)bug-ga2-mem
 endif
 
@@ -247,6 +248,11 @@ annexc-CFLAGS = -O
 $(objpfx)annexc: annexc.c
        $(native-compile)
 
+tst-fnmatch-ENV += MALLOC_TRACE=$(objpfx)tst-fnmatch.mtrace
+
+$(objpfx)tst-fnmatch-mem: $(objpfx)tst-fnmatch.out
+       $(common-objpfx)malloc/mtrace $(objpfx)tst-fnmatch.mtrace > $@
+
 bug-regex2-ENV = MALLOC_TRACE=$(objpfx)bug-regex2.mtrace
 
 $(objpfx)bug-regex2-mem: $(objpfx)bug-regex2.out
index c8e52a6b4db0dc045a185257ae8e2d2f84f3b6c6..6b0224ea2c86d8c6114787ebbea36373c5ef769c 100644 (file)
@@ -1113,11 +1113,6 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
            slen = sizeof (struct patternlist) + (slen * sizeof (CHAR));      \
            int malloced = ! __libc_use_alloca (alloca_used + slen);          \
            if (__builtin_expect (malloced, 0))                               \
-             {                                                               \
-               newp = alloca_account (slen, alloca_used);                    \
-               any_malloced = 1;                                             \
-             }                                                               \
-           else                                                              \
              {                                                               \
                newp = malloc (slen);                                         \
                if (newp == NULL)                                             \
@@ -1125,7 +1120,10 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
                    retval = -2;                                              \
                    goto out;                                                 \
                  }                                                           \
+               any_malloced = 1;                                             \
              }                                                               \
+           else                                                              \
+             newp = alloca_account (slen, alloca_used);                      \
            newp->next = NULL;                                                \
            newp->malloced = malloced;                                        \
            *((CHAR *) MEMPCPY (newp->str, startp, p - startp)) = L('\0');    \
index 25471f8e413b77f7ea842e8c0d0956d679defe97..7e1f73a975f8944351d7b8ca901c8f5237a5f7a1 100644 (file)
@@ -1,5 +1,5 @@
 /* Tests for fnmatch function.
-   Copyright (C) 2000, 2001 Free Software Foundation, Inc.
+   Copyright (C) 2000, 2001, 2010 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -25,6 +25,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
+#include <mcheck.h>
 
 
 static char *next_input (char **line, int first, int last);
@@ -46,6 +47,8 @@ main (void)
   size_t escpatternlen = 0;
   int nr = 0;
 
+  mtrace ();
+
   /* Read lines from stdin with the following format:
 
        locale  input-string  match-string  flags  result