]> git.sur5r.net Git - i3/i3/commitdiff
Bugfix: Don't segfault, if child was killed
authorAxel Wagner <mail@merovius.de>
Mon, 14 Mar 2011 08:17:06 +0000 (09:17 +0100)
committerAxel Wagner <mail@merovius.de>
Mon, 14 Mar 2011 08:17:06 +0000 (09:17 +0100)
i3bar/src/child.c

index 795a10d3e3f82edfdbd5cdecdd9aa7d18b5d1f39..890dce29b58211f29ff8d73cf6a19a51a0015d46 100644 (file)
@@ -11,6 +11,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/types.h>
+#include <sys/wait.h>
 #include <signal.h>
 #include <stdio.h>
 #include <fcntl.h>
@@ -35,11 +36,13 @@ char *statusline_buffer = NULL;
  *
  */
 void cleanup() {
-    ev_io_stop(main_loop, stdin_io);
-    ev_child_stop(main_loop, child_sig);
-    FREE(stdin_io);
-    FREE(child_sig);
-    FREE(statusline_buffer);
+    if (stdin_io != NULL) {
+        ev_io_stop(main_loop, stdin_io);
+        ev_child_stop(main_loop, child_sig);
+        FREE(stdin_io);
+        FREE(child_sig);
+        FREE(statusline_buffer);
+    }
 }
 
 /*
@@ -174,8 +177,11 @@ void kill_child() {
     if (child_pid != 0) {
         kill(child_pid, SIGCONT);
         kill(child_pid, SIGTERM);
+        int status;
+        waitpid(child_pid, &status, 0);
+        child_pid = 0;
+        cleanup();
     }
-    cleanup();
 }
 
 /*