www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2004/12/07/06:02:49

X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f
Date: Tue, 7 Dec 2004 13:02:04 +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: <41B48A8B.18253.35A9BAD@localhost>
Message-ID: <Pine.OSF.4.58.0412071254320.19658@sirppi.helsinki.fi>
References: <q1h2r0dl6evues7nrvo6r9g5j6dv2u57sm AT 4ax DOT com> (message from Brian
Inglis on Fri, 03 Dec 2004 22:02:18 -0700) <41B48A8B DOT 18253 DOT 35A9BAD 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 Mon, 6 Dec 2004, Juan Manuel Guerrero wrote:

> diff -arNU5 djgpp.orig/src/libc/posix/stdio/popen.c djgpp/src/libc/posix/stdio/popen.c
> --- djgpp.orig/src/libc/posix/stdio/popen.c	2004-11-30 05:08:20.000000000 +0000
> +++ djgpp/src/libc/posix/stdio/popen.c	2004-12-04 18:24:54.000000000 +0000
> @@ -76,10 +76,11 @@
>    char *temp_name;
>
>    /* make new node */
>    if ((l1 = malloc(sizeof(*l1))) == NULL)
>      return NULL;
> +  l1->command = NULL;

I just committed a different patch (mostly because I think the real bug
is trying to free the command pointer in read mode at all):

Index: popen.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/posix/stdio/popen.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- popen.c	29 Nov 2004 08:37:03 -0000	1.7
+++ popen.c	7 Dec 2004 10:53:51 -0000	1.8
@@ -232,6 +232,10 @@

     /* close duplicate stdin */
     close(fd);
+
+  exit:
+
+    free(l1->command);
   }
   /* if pipe was opened to read, return the exit status we saved */
   else if (l1->mode[0] == 'r')
@@ -245,11 +249,6 @@
     /* invalid mode */
     retval = -1;

- exit:
-
-  if (l1->command)
-    free(l1->command);
-
   free(l1);

   return retval;

-- 
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