From 2762f7377913e766817a8ae91d4959cbac022aaf Mon Sep 17 00:00:00 2001 From: Andrew Hutchings Date: Thu, 9 Oct 2014 11:07:28 +0100 Subject: [PATCH] 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. --- src/unix/loop.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/unix/loop.c b/src/unix/loop.c index 002224855c..b0d445fd41 100644 --- a/src/unix/loop.c +++ b/src/unix/loop.c @@ -139,14 +139,26 @@ static int uv__loop_init(uv_loop_t* loop, int default_loop) { loop->child_watcher.flags |= UV__HANDLE_INTERNAL; QUEUE_INIT(&loop->process_handles); - if (uv_rwlock_init(&loop->cloexec_lock)) - abort(); + err = uv_rwlock_init(&loop->cloexec_lock); + if (err) { + uv__platform_loop_delete(loop); + return err; + } - if (uv_mutex_init(&loop->wq_mutex)) - abort(); + err = uv_mutex_init(&loop->wq_mutex); + if (err) { + uv__platform_loop_delete(loop); + uv_rwlock_destroy(&loop->cloexec_lock); + return err; + } - if (uv_async_init(loop, &loop->wq_async, uv__work_done)) - abort(); + err = uv_async_init(loop, &loop->wq_async, uv__work_done); + if (err) { + uv__platform_loop_delete(loop); + uv_rwlock_destroy(&loop->cloexec_lock); + uv_mutex_destroy(&loop->wq_mutex); + return err; + } uv__handle_unref(&loop->wq_async); loop->wq_async.flags |= UV__HANDLE_INTERNAL;