make popen cancellation-safe
authorRich Felker <dalias@aerifal.cx>
Wed, 20 Jun 2012 18:39:50 +0000 (14:39 -0400)
committerRich Felker <dalias@aerifal.cx>
Wed, 20 Jun 2012 18:39:50 +0000 (14:39 -0400)
close was the only cancellation point called from popen, but it left
popen with major resource leaks if any call to close got cancelled.
the easiest, cheapest fix is just to use a non-cancellable close
function.

src/stdio/popen.c

index 50765da..4f9d6e9 100644 (file)
@@ -1,4 +1,11 @@
 #include "stdio_impl.h"
 #include "stdio_impl.h"
+#include "syscall.h"
+
+static inline void nc_close(int fd)
+{
+       __syscall(SYS_close, fd);
+}
+#define close(x) nc_close(x)
 
 FILE *popen(const char *cmd, const char *mode)
 {
 
 FILE *popen(const char *cmd, const char *mode)
 {