Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: fc resource leak



CID 128. In this case, a temporary file is not being closed when an
error condition occurs. Even though the file is deleted, it is still open.

Doing ls -l /proc/$$/fd on Linux makes it easy to see the open deleted
files. Running fc with the current event number prints a message to warn
about "current history line would recurse endlessly, aborted". Coverity
doesn't notice it but the same problem applies to two further error
messages down in the fclist() function.

Oliver

Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.217
diff -u -r1.217 builtin.c
--- Src/builtin.c	5 Nov 2008 13:02:09 -0000	1.217
+++ Src/builtin.c	12 Nov 2008 10:23:53 -0000
@@ -1480,6 +1480,7 @@
 		    unqueue_signals();
 		    zwarnnam("fc",
 		      "current history line would recurse endlessly, aborted");
+                    fclose(out);
 		    unlink(fil);
 		    return 1;
 		}
@@ -1619,6 +1620,8 @@
 	    zwarnnam("fc", "no such event: %s", buf);
 	} else
 	    zwarnnam("fc", "no events in that range");
+        if (f != stdout)
+	    fclose(f);
 	return 1;
     }
 




Messages sorted by: Reverse Date, Date, Thread, Author