]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Make sure we call process_notify_event_exit() as the last thing in different callbacks.
authorAlexander Færøy <ahf@torproject.org>
Thu, 22 Nov 2018 17:14:03 +0000 (18:14 +0100)
committerNick Mathewson <nickm@torproject.org>
Mon, 17 Dec 2018 21:39:28 +0000 (16:39 -0500)
This patch makes sure that we call process_notify_event_exit() after we
have done any modifications we need to do to the state of a process_t.
This allows application developers to call process_free() in the
exit_callback of the process.

See: https://bugs.torproject.org/28179

src/lib/process/process_unix.c
src/lib/process/process_win32.c

index fa03fdbbe42140a51a2194604032b258313bf576..4f46bbd888e03efd370f84b6ebf909c7ce2e8e48 100644 (file)
@@ -549,12 +549,16 @@ process_unix_waitpid_callback(int status, void *data)
   process_t *process = data;
   process_unix_t *unix_process = process_get_unix_process(process);
 
-  /* Notify our process. */
-  process_notify_event_exit(process, status);
-
   /* Remove our waitpid callback. */
   clear_waitpid_callback(unix_process->waitpid);
   unix_process->waitpid = NULL;
+
+  /* Notify our process. */
+  process_notify_event_exit(process, status);
+
+  /* Make sure you don't modify the process after we have called
+   * process_notify_event_exit() on it, to allow users to process_free() it in
+   * the exit callback. */
 }
 
 /** This function sets the file descriptor in the <b>handle</b> as non-blocking
index 3e97f378010f56c905d44bcdc803e69d2146ea9c..7422493deb1d51231e8a29bda55427201486f1cf 100644 (file)
@@ -445,12 +445,15 @@ process_win32_timer_callback(periodic_timer_t *timer, void *data)
   tor_assert(data == NULL);
 
   log_debug(LD_PROCESS, "Windows Process I/O timer ticked");
+
+  /* Move the process into an alertable state. */
+  process_win32_trigger_completion_callbacks();
+
+  /* Check if our processes are still alive. */
   const smartlist_t *processes = process_get_all_processes();
 
   SMARTLIST_FOREACH(processes, process_t *, p,
                     process_win32_timer_test_process(p));
-
-  process_win32_trigger_completion_callbacks();
 }
 
 /** Test whether a given process is still alive. Notify the Process subsystem