aboutsummaryrefslogtreecommitdiff
path: root/src/unix/linux.c
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2025-04-18 16:23:51 +0200
committerGitHub <noreply@github.com>2025-04-18 16:23:51 +0200
commit942e1418ea235e419a520491b00fe8a96426a5fa (patch)
tree8f6c27b19366acd38ac3eae5c9e4eebeac793065 /src/unix/linux.c
parent11ecfbad8175dc4d754600109c7a9a5b3f30fc80 (diff)
downloadlibuv-942e1418ea235e419a520491b00fe8a96426a5fa.tar.gz
libuv-942e1418ea235e419a520491b00fe8a96426a5fa.zip
unix: improve uv_loop_init OOM handling (#4757)
Handle out-of-memory conditions in uv_loop_init better, albeit still not perfect: bubble up the error instead of aborting. Also fixes a file descriptor leak on Linux (and likely other platforms) that the new test caught; the backend epoll fd was being leaked in the error path. Fixes: https://github.com/libuv/libuv/issues/4755
Diffstat (limited to 'src/unix/linux.c')
-rw-r--r--src/unix/linux.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/unix/linux.c b/src/unix/linux.c
index 86c12b4f..5fa4627d 100644
--- a/src/unix/linux.c
+++ b/src/unix/linux.c
@@ -2460,6 +2460,7 @@ static int compare_watchers(const struct watcher_list* a,
static int init_inotify(uv_loop_t* loop) {
+ int err;
int fd;
if (loop->inotify_fd != -1)
@@ -2469,10 +2470,14 @@ static int init_inotify(uv_loop_t* loop) {
if (fd < 0)
return UV__ERR(errno);
- loop->inotify_fd = fd;
- uv__io_init(&loop->inotify_read_watcher, uv__inotify_read, loop->inotify_fd);
- uv__io_start(loop, &loop->inotify_read_watcher, POLLIN);
+ err = uv__io_init_start(loop, &loop->inotify_read_watcher, uv__inotify_read,
+ fd, POLLIN);
+ if (err) {
+ uv__close(fd);
+ return err;
+ }
+ loop->inotify_fd = fd;
return 0;
}