]> mj.ucw.cz Git - libucw.git/commitdiff
Main: main_delete() must make the soon-to-be-deleted context current
authorMartin Mares <mj@ucw.cz>
Fri, 25 Feb 2011 23:23:25 +0000 (00:23 +0100)
committerMartin Mares <mj@ucw.cz>
Fri, 25 Feb 2011 23:23:25 +0000 (00:23 +0100)
Otherwise, it might call signal_del() and file_del() on another
(or even undefined) context.

ucw/mainloop.c

index bf72f943145cd5e3460e89df8caf88c3f082ed05..6575210b2665baf7fc5e2cc2cfd267e8d5218fe2 100644 (file)
@@ -83,6 +83,8 @@ main_new(void)
 void
 main_delete(struct main_context *m)
 {
+  struct main_context *prev = main_switch_context(m);
+
   if (m->sigchld_handler)
     signal_del(m->sigchld_handler);
   if (m->sig_pipe_file)
@@ -109,6 +111,8 @@ main_delete(struct main_context *m)
 #endif
   xfree(m);
   // FIXME: Some mechanism for cleaning up after fork()
+
+  main_switch_context((prev == m) ? NULL : prev);
 }
 
 struct main_context *
@@ -150,8 +154,7 @@ main_init(void)
 void
 main_cleanup(void)
 {
-  struct main_context *m = main_switch_context(NULL);
-  main_delete(m);
+  main_delete(main_current());
 }
 
 void