summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schwab <schwab@redhat.com>2010-11-12 03:51:28 -0500
committerAndreas Schwab <schwab@redhat.com>2010-12-01 15:35:18 +0100
commit8cef0b4a129dba0b4cc93073b423cca270ed9cbb (patch)
treee11d8fab14c7ac3467a82d16f1de49cac1744b2c
parentf925c225e4c523c00decc78ad023feb29c533d84 (diff)
downloadglibc-8cef0b4a129dba0b4cc93073b423cca270ed9cbb.tar.gz
Fix memory leak in fnmatch
(cherry picked from commit 3540d66b669af54900b2e4bfc0ab82960e84a471)
-rw-r--r--ChangeLog9
-rw-r--r--posix/Makefile10
-rw-r--r--posix/fnmatch_loop.c8
-rw-r--r--posix/tst-fnmatch.c5
4 files changed, 24 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 9e9e59fbe8..8bb1b600b6 100644
--- 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-08-09 Ulrich Drepper <drepper@redhat.com>
[BZ #11883]
diff --git a/posix/Makefile b/posix/Makefile
index 0fe65361a7..dff6b51e30 100644
--- a/posix/Makefile
+++ b/posix/Makefile
@@ -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
@@ -227,7 +228,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
@@ -239,6 +240,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
diff --git a/posix/fnmatch_loop.c b/posix/fnmatch_loop.c
index c8e52a6b4d..6b0224ea2c 100644
--- a/posix/fnmatch_loop.c
+++ b/posix/fnmatch_loop.c
@@ -1114,18 +1114,16 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
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) \
{ \
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'); \
diff --git a/posix/tst-fnmatch.c b/posix/tst-fnmatch.c
index 25471f8e41..7e1f73a975 100644
--- a/posix/tst-fnmatch.c
+++ b/posix/tst-fnmatch.c
@@ -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