win,sunos: stop handle on uv_fs_event_start() err

This commit stops the handle in uv_fs_event_start() when an
error occurs.

Fixes: https://github.com/libuv/libuv/issues/1253
PR-URL: https://github.com/libuv/libuv/pull/1257
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
This commit is contained in:
cjihrig 2017-03-16 21:20:11 -04:00
parent 7e36c94e56
commit 463800ffc1
4 changed files with 26 additions and 1 deletions

View File

@ -481,8 +481,10 @@ int uv_fs_event_start(uv_fs_event_t* handle,
memset(&handle->fo, 0, sizeof handle->fo);
handle->fo.fo_name = handle->path;
err = uv__fs_event_rearm(handle);
if (err != 0)
if (err != 0) {
uv_fs_event_stop(handle);
return err;
}
if (first_run) {
uv__io_init(&handle->loop->fs_event_watcher, uv__fs_event_read, portfd);

View File

@ -306,6 +306,9 @@ error:
handle->buffer = NULL;
}
if (uv__is_active(handle))
uv__handle_stop(handle);
return uv_translate_sys_error(last_error);
}

View File

@ -1027,3 +1027,21 @@ TEST_IMPL(fs_event_error_reporting) {
}
#endif /* defined(__APPLE__) */
TEST_IMPL(fs_event_watch_invalid_path) {
#if defined(MVS)
RETURN_SKIP("Filesystem watching not supported on this platform.");
#endif
uv_loop_t* loop;
int r;
loop = uv_default_loop();
r = uv_fs_event_init(loop, &fs_event);
ASSERT(r == 0);
r = uv_fs_event_start(&fs_event, fs_event_cb_file, "<:;", 0);
ASSERT(r != 0);
ASSERT(uv_is_active((uv_handle_t*) &fs_event) == 0);
MAKE_VALGRIND_HAPPY();
return 0;
}

View File

@ -287,6 +287,7 @@ TEST_DECLARE (fs_event_watch_file_current_dir)
#ifdef _WIN32
TEST_DECLARE (fs_event_watch_file_root_dir)
#endif
TEST_DECLARE (fs_event_watch_invalid_path)
TEST_DECLARE (fs_event_no_callback_after_close)
TEST_DECLARE (fs_event_no_callback_on_close)
TEST_DECLARE (fs_event_immediate_close)
@ -764,6 +765,7 @@ TASK_LIST_START
#ifdef _WIN32
TEST_ENTRY (fs_event_watch_file_root_dir)
#endif
TEST_ENTRY (fs_event_watch_invalid_path)
TEST_ENTRY (fs_event_no_callback_after_close)
TEST_ENTRY (fs_event_no_callback_on_close)
TEST_ENTRY (fs_event_immediate_close)