From 09ba4778d8a8d36b652c714c2cc6557b7e945ee2 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 21 Feb 2019 12:32:44 +0100 Subject: [PATCH] bsd: plug uv_fs_event_start() error path fd leak MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: Santiago Gimeno Reviewed-By: Saúl Ibarra Corretgé --- src/unix/kqueue.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/unix/kqueue.c b/src/unix/kqueue.c index 38c88d7d..09200516 100644 --- a/src/unix/kqueue.c +++ b/src/unix/kqueue.c @@ -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);