From da0b84d4e8408a6f92147d8127b01b3274215444 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 22 Feb 2013 14:39:39 +0100 Subject: [PATCH] unix: auto-unref spawn handle on process exit Consistent, for better or worse, with uv-win. Fixes #718. --- src/unix/process.c | 2 ++ test/test-list.h | 2 ++ test/test-spawn.c | 13 +++++++++++++ 3 files changed, 17 insertions(+) diff --git a/src/unix/process.c b/src/unix/process.c index 4c5714fa..267ecb64 100644 --- a/src/unix/process.c +++ b/src/unix/process.c @@ -89,6 +89,8 @@ static void uv__chld(uv_signal_t* handle, int signum) { if (process == NULL) continue; /* XXX bug? abort? */ + uv__handle_stop(process); + if (process->exit_cb == NULL) continue; diff --git a/test/test-list.h b/test/test-list.h index efc97380..6c7da04c 100644 --- a/test/test-list.h +++ b/test/test-list.h @@ -152,6 +152,7 @@ TEST_DECLARE (spawn_preserve_env) TEST_DECLARE (spawn_setuid_fails) TEST_DECLARE (spawn_setgid_fails) TEST_DECLARE (spawn_stdout_to_file) +TEST_DECLARE (spawn_auto_unref) TEST_DECLARE (fs_poll) TEST_DECLARE (kill) TEST_DECLARE (fs_file_noent) @@ -413,6 +414,7 @@ TASK_LIST_START TEST_ENTRY (spawn_setuid_fails) TEST_ENTRY (spawn_setgid_fails) TEST_ENTRY (spawn_stdout_to_file) + TEST_ENTRY (spawn_auto_unref) TEST_ENTRY (fs_poll) TEST_ENTRY (kill) diff --git a/test/test-spawn.c b/test/test-spawn.c index a93e8763..56eca9c5 100644 --- a/test/test-spawn.c +++ b/test/test-spawn.c @@ -923,3 +923,16 @@ TEST_IMPL(spawn_setgid_fails) { return 0; } #endif + + +TEST_IMPL(spawn_auto_unref) { + init_process_options("spawn_helper1", NULL); + ASSERT(0 == uv_spawn(uv_default_loop(), &process, options)); + ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT)); + ASSERT(0 == uv_is_closing((uv_handle_t*) &process)); + uv_close((uv_handle_t*) &process, NULL); + ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT)); + ASSERT(0 != uv_is_closing((uv_handle_t*) &process)); + MAKE_VALGRIND_HAPPY(); + return 0; +}