From 3e76e47304aa4cf1cdf4cfe3368146699ccc6178 Mon Sep 17 00:00:00 2001 From: Brandon Cheng Date: Sat, 13 Mar 2021 18:36:06 -0500 Subject: [PATCH] darwin: abort on pthread_attr_init fail `pthread_attr_init` is highly unlikely to fail on macOS. Removing the fallback behavior here to be consistent with other parts of libuv (e.g. `src/unix/thread.c`), which simply call `abort()`. PR-URL: https://github.com/libuv/libuv/pull/3132 Reviewed-By: Ben Noordhuis Reviewed-By: Santiago Gimeno --- src/unix/fsevents.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/unix/fsevents.c b/src/unix/fsevents.c index e4d1b416..bf4f1f6a 100644 --- a/src/unix/fsevents.c +++ b/src/unix/fsevents.c @@ -595,8 +595,7 @@ out: static int uv__fsevents_loop_init(uv_loop_t* loop) { CFRunLoopSourceContext ctx; uv__cf_loop_state_t* state; - pthread_attr_t attr_storage; - pthread_attr_t* attr; + pthread_attr_t attr; int err; if (loop->cf_state != NULL) @@ -641,25 +640,19 @@ static int uv__fsevents_loop_init(uv_loop_t* loop) { goto fail_signal_source_create; } - /* In the unlikely event that pthread_attr_init() fails, create the thread - * with the default stack size. We'll likely use less address space but that - * in itself is not a fatal error. - */ - attr = &attr_storage; - if (pthread_attr_init(attr)) - attr = NULL; + if (pthread_attr_init(&attr)) + abort(); - if (attr != NULL) - if (pthread_attr_setstacksize(attr, uv__thread_stack_size())) - abort(); + if (pthread_attr_setstacksize(&attr, uv__thread_stack_size())) + abort(); loop->cf_state = state; /* uv_thread_t is an alias for pthread_t. */ - err = UV__ERR(pthread_create(&loop->cf_thread, attr, uv__cf_loop_runner, loop)); + err = UV__ERR(pthread_create(&loop->cf_thread, &attr, uv__cf_loop_runner, loop)); - if (attr != NULL) - pthread_attr_destroy(attr); + if (pthread_attr_destroy(&attr)) + abort(); if (err) goto fail_thread_create;