svn commit: r246356 - in stable: 7/lib/libc/gen 8/lib/libc/gen 9/lib/libc/gen

Xin LI delphij at
Tue Feb 5 09:50:34 UTC 2013

Author: delphij
Date: Tue Feb  5 09:50:33 2013
New Revision: 246356

  MFC r243758 (marcel):
  In globextend() when the pathv vector cannot be (re-)allocated, don't
  free and clear the gl_pathv pointer in the glob_t structure. Such
  breaks the invariant of the glob_t structure, as stated in the comment
  right in front of the globextend() function. If gl_pathv was non-NULL,
  then gl_pathc was > 0. Making gl_pathv a NULL pointer without also
  setting gl_pathc to 0 is wrong.
  Since we otherwise don't free the memory associated with a glob_t in
  error cases, it's unlikely that this change will cause a memory leak
  that wasn't already there to begin with. Callers of glob(3) must
  call globfree(3) irrespective of whether glob(3) returned an error
  or not.
  MFC r243759 (marcel):
  In globextend(), take advantage of the fact that realloc(NULL, size) is
  equivalent to malloc(size). This eliminates the conditional expression
  used for calling either realloc() or malloc() when realloc() will do
  all the time.

Directory Properties:
  stable/8/lib/libc/   (props changed)

Changes in other areas also in this revision:
Directory Properties:
  stable/7/lib/libc/   (props changed)
  stable/9/lib/libc/   (props changed)

Modified: stable/8/lib/libc/gen/glob.c
--- stable/8/lib/libc/gen/glob.c	Tue Feb  5 09:40:31 2013	(r246355)
+++ stable/8/lib/libc/gen/glob.c	Tue Feb  5 09:50:33 2013	(r246356)
@@ -710,16 +710,10 @@ globextend(const Char *path, glob_t *pgl
 	newsize = sizeof(*pathv) * (2 + pglob->gl_pathc + pglob->gl_offs);
-	pathv = pglob->gl_pathv ?
-		    realloc((char *)pglob->gl_pathv, newsize) :
-		    malloc(newsize);
-	if (pathv == NULL) {
-		if (pglob->gl_pathv) {
-			free(pglob->gl_pathv);
-			pglob->gl_pathv = NULL;
-		}
+	/* realloc(NULL, newsize) is equivalent to malloc(newsize). */
+	pathv = realloc((void *)pglob->gl_pathv, newsize);
+	if (pathv == NULL)
-	}
 	if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) {
 		/* first time around -- clear initial gl_offs items */

More information about the svn-src-stable-8 mailing list