From: Ulrich Drepper Date: Sat, 30 Sep 2006 15:09:35 +0000 (+0000) Subject: * posix/glob.c (glob_in_dir): Add some comments and asserts to X-Git-Tag: cvs/fedora-glibc-20061002T1858~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f01e40699cc30cbaca756ecae6e08718d7530d20;p=thirdparty%2Fglibc.git * posix/glob.c (glob_in_dir): Add some comments and asserts to explain why there are no leaks. --- diff --git a/ChangeLog b/ChangeLog index 22f5067f2d0..d78dffcfa01 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2006-09-30 Ulrich Drepper + + * posix/glob.c (glob_in_dir): Add some comments and asserts to + explain why there are no leaks. + 2006-09-29 Ulrich Drepper * libio/wmemstream.c: Include . diff --git a/libio/bug-wmemstream1.c b/libio/bug-wmemstream1.c index 2190593c933..22d67f71e93 100644 --- a/libio/bug-wmemstream1.c +++ b/libio/bug-wmemstream1.c @@ -1,5 +1,6 @@ #include #include +#include static int diff --git a/libio/tst-wmemstream1.c b/libio/tst-wmemstream1.c index 0c59c1adcba..f8b308bc6cc 100644 --- a/libio/tst-wmemstream1.c +++ b/libio/tst-wmemstream1.c @@ -1,3 +1,5 @@ +#include + #define CHAR_T wchar_t #define W(o) L##o #define OPEN_MEMSTREAM open_wmemstream diff --git a/libio/tst-wmemstream2.c b/libio/tst-wmemstream2.c index f51a1db20c0..e2442ebfac7 100644 --- a/libio/tst-wmemstream2.c +++ b/libio/tst-wmemstream2.c @@ -1,3 +1,5 @@ +#include + #define CHAR_T wchar_t #define W(o) L##o #define OPEN_MEMSTREAM open_wmemstream diff --git a/libio/wmemstream.c b/libio/wmemstream.c index 85ea64991a8..577931888de 100644 --- a/libio/wmemstream.c +++ b/libio/wmemstream.c @@ -20,6 +20,7 @@ #include "strfile.h" #include #include +#include struct _IO_FILE_wmemstream diff --git a/posix/glob.c b/posix/glob.c index 630d54063ae..0079a15a929 100644 --- a/posix/glob.c +++ b/posix/glob.c @@ -1287,8 +1287,15 @@ glob_in_dir (const char *pattern, const char *directory, int flags, for (size_t i = 0; i < cur; ++i) free (names->name[i]); names = names->next; + /* NB: we will not leak memory here if we exit without + freeing the current block assigned to OLD. At least + the very first block is always allocated on the stack + and this is the block assigned to OLD here. */ if (names == NULL) - break; + { + assert (old == &init_names); + break; + } cur = names->count; if (old == names_alloca) names_alloca = names; @@ -1306,8 +1313,15 @@ glob_in_dir (const char *pattern, const char *directory, int flags, new_gl_pathv[pglob->gl_offs + pglob->gl_pathc++] = names->name[i]; names = names->next; + /* NB: we will not leak memory here if we exit without + freeing the current block assigned to OLD. At least + the very first block is always allocated on the stack + and this is the block assigned to OLD here. */ if (names == NULL) - break; + { + assert (old == &init_names); + break; + } cur = names->count; if (old == names_alloca) names_alloca = names;