bsd: plug uv_fs_event_start() error path fd leak

Close the watched file's file descriptor when initialization fails due
to out-of-memory conditions.

PR-URL: https://github.com/libuv/libuv/pull/2197
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
This commit is contained in:
Ben Noordhuis 2019-02-21 12:32:44 +01:00
parent bcef1c16fb
commit 09ba4778d8

View File

@ -490,8 +490,11 @@ int uv_fs_event_start(uv_fs_event_t* handle,
return UV__ERR(errno);
handle->path = uv__strdup(path);
if (handle->path == NULL)
if (handle->path == NULL) {
uv__close_nocheckstdio(fd);
return UV_ENOMEM;
}
handle->cb = cb;
uv__handle_start(handle);
uv__io_init(&handle->event_watcher, uv__fs_event, fd);