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

Commit

Permalink
unix: don't abort loop initalization
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LinuxJedi committed Oct 9, 2014
1 parent 471e844 commit 2762f73
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/unix/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2762f73

Please sign in to comment.