nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Nano-devel] 1.0.8 Memory leaks . . . and fixes


From: Rocco Corsi
Subject: Re: [Nano-devel] 1.0.8 Memory leaks . . . and fixes
Date: Mon, 25 Mar 2002 00:39:12 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.2.1) Gecko/20010901

Dwayne Rightler wrote:

We should definately throw a wait(NULL) call in after the execl() in
open_pipe()...




I have attached a patch that fixes the wait() problem and also closes the pipe in the case of fork() failure.

Rocco




Index: files.c
===================================================================
RCS file: /cvsroot/nano/nano/files.c,v
retrieving revision 1.154
diff -u -r1.154 files.c
--- files.c     21 Mar 2002 23:39:56 -0000      1.154
+++ files.c     25 Mar 2002 05:31:15 -0000
@@ -292,6 +292,7 @@
 int open_pipe(char *command)
 {
     int fd[2], pid;
+    int fork_status;
   
   /* Make our pipes. */
 
@@ -311,15 +312,22 @@
        execl("/bin/sh","/bin/sh","-c",command,0);
        exit(0);
     }
-    else if (pid == -1) {
+
+    /* Else continue as parent */
+
+    close(fd[1]);
+
+    if (pid == -1) {
+       close(fd[0]);
        statusbar(_("Could not fork"));
        return 1;
     }
 
-    /* Else continue as parent */
-    close(fd[1]);
     read_file(fd[0],"stdin",0);
     set_modified();
+
+    wait(&fork_status);
+
     return 0;
 }
 #endif /* NANO_SMALL */

reply via email to

[Prev in Thread] Current Thread [Next in Thread]