This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: glob must not call globfree


On Sat, Feb 09, Andreas Schwab wrote:

> Ulrich Drepper <drepper@redhat.com> writes:
> 
> |> Andreas Schwab <schwab@suse.de> writes:
> |> 
> |> > I don't understand what you are trying to say.  Could you please clearify
> |> > what this issue has to do with INTDEF/INTUSE?
> |> 
> |> If glob uses the globfree function via the INTUSE macro the call isn't
> |> visible from the outside.
> 
> You do not understand.  glob must *not* call globfree.  See POSIX.

I think at first we should clearify the problem:

In error case, we return a struct, where gl_pathc is not zero and
gl_pathv is undefined (because of the globfree before). According to
POSIX, this is wrong, even in error case the struct must have defined
values.
In the moment our problem is, if a program calls correct globfree(),
the program will seg.fault, because gl_pathc is not zero, but gl_pathv
is undefined what is not allowed according to POSIX.
If we apply Andreas Schwab patch, current, working programs will have
a memory leak.

I think the problem is our globfree: If called, it only checks if
gl_pathv is not NULL. I think it should also check, that gl_pathc
is not zero and set it to zero after freeing gl_pathv. This fixes
all of our current problems with this.

I suggest the following patch:

2002-02-09  Thorsten Kukuk  <kukuk@suse.de>

	* sysdeps/generic/glob.c (globfree): Only free memory if
	gl_pathc is not zero, set gl_pathc to zero afterwards.

--- sysdeps/generic/glob.c
+++ sysdeps/generic/glob.c	2002/02/09 15:00:04
@@ -1056,7 +1056,7 @@
 globfree (pglob)
      register glob_t *pglob;
 {
-  if (pglob->gl_pathv != NULL)
+  if (pglob->gl_pathc && pglob->gl_pathv != NULL)
     {
       size_t i;
       for (i = 0; i < pglob->gl_pathc; ++i)
@@ -1064,6 +1064,7 @@
 	  free ((__ptr_t) pglob->gl_pathv[pglob->gl_offs + i]);
       free ((__ptr_t) pglob->gl_pathv);
     }
+  pglob->gl_pathc = 0;
 }

-- 
Thorsten Kukuk       http://www.suse.de/~kukuk/        kukuk@suse.de
SuSE GmbH            Deutschherrenstr. 15-19       D-90429 Nuernberg
--------------------------------------------------------------------    
Key fingerprint = A368 676B 5E1B 3E46 CFCE  2D97 F8FD 4E23 56C6 FB4B


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]