www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2004/12/08/03:55:14

X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f
Date: Wed, 8 Dec 2004 10:55:08 +0200 (EET)
From: Esa A E Peuha <peuha AT cc DOT helsinki DOT fi>
Sender: peuha AT sirppi DOT helsinki DOT fi
To: djgpp-workers AT delorie DOT com
Subject: Re: A fix for popen()
In-Reply-To: <41B5E51B.9304.37DF4A0@localhost>
Message-ID: <Pine.OSF.4.58.0412081042170.1168@sirppi.helsinki.fi>
References: <Pine DOT OSF DOT 4 DOT 58 DOT 0412071254320 DOT 19658 AT sirppi DOT helsinki DOT fi> (message
from Esa A E Peuha on Tue, 7 Dec 2004 13:02:04 +0200 (EET))
<41B5E51B DOT 9304 DOT 37DF4A0 AT localhost>
MIME-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Tue, 7 Dec 2004, Juan Manuel Guerrero wrote:

> The important issue here is the to notice that the patch proposed by Esa
> this morning still does not resolve the complete issue. The patch inhibits
> the call to free() in pclose but left the same malign code:
>  error:
>
>   if (l1->command)
>     free(l1->command);
>
>   if (temp_name)
>     free(temp_name);
>
> in popen().

Did you actually see crashes from freeing temp_name?  I don't see how
that could happen, since temp_name will be initialized in any case.
However, freeing the command pointer is completely unnecessary (read
mode doesn't allocate it, write mode jumps there only when it's already
null), so I removed it.

Index: popen.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/posix/stdio/popen.c,v
retrieving revision 1.8
diff -u -r1.8 popen.c
--- popen.c	7 Dec 2004 10:53:51 -0000	1.8
+++ popen.c	8 Dec 2004 08:38:56 -0000
@@ -84,6 +84,8 @@
   pl = l1;

   /* stick in elements we know already */
+  l1->command = NULL;
+
   if ((temp_name = malloc(L_tmpnam)) == NULL)
     goto error;

@@ -154,9 +156,6 @@

  error:

-  if (l1->command)
-    free(l1->command);
-
   if (temp_name)
     free(temp_name);



-- 
Esa Peuha
student of mathematics at the University of Helsinki
http://www.helsinki.fi/~peuha/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019