Skip to content
This repository was archived by the owner on May 4, 2018. It is now read-only.

Commit 2762f73

Browse files
committed
unix: don't abort loop initalization
There are several conditions which could cause uv_loop_init() (and by extension uv_loop_new()) to trigger an SIGABRT. This includes mutex initialization failure or running out of FDs. This patch removes the abort()s and returns error codes instead. Cleaning up prior initialization if something has actually failed.
1 parent 471e844 commit 2762f73

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/unix/loop.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,26 @@ static int uv__loop_init(uv_loop_t* loop, int default_loop) {
139139
loop->child_watcher.flags |= UV__HANDLE_INTERNAL;
140140
QUEUE_INIT(&loop->process_handles);
141141

142-
if (uv_rwlock_init(&loop->cloexec_lock))
143-
abort();
142+
err = uv_rwlock_init(&loop->cloexec_lock);
143+
if (err) {
144+
uv__platform_loop_delete(loop);
145+
return err;
146+
}
144147

145-
if (uv_mutex_init(&loop->wq_mutex))
146-
abort();
148+
err = uv_mutex_init(&loop->wq_mutex);
149+
if (err) {
150+
uv__platform_loop_delete(loop);
151+
uv_rwlock_destroy(&loop->cloexec_lock);
152+
return err;
153+
}
147154

148-
if (uv_async_init(loop, &loop->wq_async, uv__work_done))
149-
abort();
155+
err = uv_async_init(loop, &loop->wq_async, uv__work_done);
156+
if (err) {
157+
uv__platform_loop_delete(loop);
158+
uv_rwlock_destroy(&loop->cloexec_lock);
159+
uv_mutex_destroy(&loop->wq_mutex);
160+
return err;
161+
}
150162

151163
uv__handle_unref(&loop->wq_async);
152164
loop->wq_async.flags |= UV__HANDLE_INTERNAL;

0 commit comments

Comments
 (0)