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 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: References: (message from Brian Inglis on Fri, 03 Dec 2004 22:02:18 -0700) <41B48A8B DOT 18253 DOT 35A9BAD AT localhost> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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 Precedence: bulk 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/