diff --git a/src/unix/sunos.c b/src/unix/sunos.c index 744fea77..48b1fca1 100644 --- a/src/unix/sunos.c +++ b/src/unix/sunos.c @@ -376,7 +376,7 @@ int uv_fs_event_init(uv_loop_t* loop, void uv__fs_event_close(uv_fs_event_t* handle) { - if (handle->fd == PORT_FIRED) { + if (handle->fd == PORT_FIRED || handle->fd == PORT_LOADED) { port_dissociate(handle->loop->fs_fd, PORT_SOURCE_FILE, (uintptr_t)&handle->fo); } handle->fd = PORT_DELETED; diff --git a/test/test-fs-event.c b/test/test-fs-event.c index 67f94219..249af9ac 100644 --- a/test/test-fs-event.c +++ b/test/test-fs-event.c @@ -296,6 +296,37 @@ TEST_IMPL(fs_event_watch_file_current_dir) { return 0; } +TEST_IMPL(fs_event_no_callback_after_close) { + uv_loop_t* loop = uv_default_loop(); + int r; + + /* Setup */ + remove("watch_dir/file1"); + remove("watch_dir/"); + create_dir(loop, "watch_dir"); + create_file(loop, "watch_dir/file1"); + + r = uv_fs_event_init(loop, + &fs_event, + "watch_dir/file1", + fs_event_cb_file, + 0); + ASSERT(r != -1); + + uv_close((uv_handle_t*)&fs_event, close_cb); + touch_file(loop, "watch_dir/file1"); + uv_run(loop); + + ASSERT(fs_event_cb_called == 0); + ASSERT(close_cb_called == 1); + + /* Cleanup */ + remove("watch_dir/file1"); + remove("watch_dir/"); + + MAKE_VALGRIND_HAPPY(); + return 0; +} TEST_IMPL(fs_event_no_callback_on_close) { uv_loop_t* loop = uv_default_loop(); diff --git a/test/test-list.h b/test/test-list.h index 82a96a03..9c59a2d4 100644 --- a/test/test-list.h +++ b/test/test-list.h @@ -177,6 +177,7 @@ TEST_DECLARE (fs_event_watch_dir) TEST_DECLARE (fs_event_watch_file) TEST_DECLARE (fs_event_watch_file_twice) TEST_DECLARE (fs_event_watch_file_current_dir) +TEST_DECLARE (fs_event_no_callback_after_close) TEST_DECLARE (fs_event_no_callback_on_close) TEST_DECLARE (fs_event_immediate_close) TEST_DECLARE (fs_event_close_with_pending_event) @@ -450,6 +451,7 @@ TASK_LIST_START TEST_ENTRY (fs_event_watch_file) TEST_ENTRY (fs_event_watch_file_twice) TEST_ENTRY (fs_event_watch_file_current_dir) + TEST_ENTRY (fs_event_no_callback_after_close) TEST_ENTRY (fs_event_no_callback_on_close) TEST_ENTRY (fs_event_immediate_close) TEST_ENTRY (fs_event_close_with_pending_event)