(glob_in_dir): Add some comments to explain why there are no leaks.
authordrepper <drepper>
Sat, 30 Sep 2006 15:08:44 +0000 (15:08 +0000)
committerdrepper <drepper>
Sat, 30 Sep 2006 15:08:44 +0000 (15:08 +0000)
posix/glob.c

index 630d540..0079a15 100644 (file)
@@ -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;