From: Waldemar Zimpel Date: Thu, 27 Mar 2025 22:15:05 +0000 (+0100) Subject: Fix: Crash on SIGSEGV if at least one worker thread cannot be launched X-Git-Tag: tor-0.4.9.2-alpha~3^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f79afc54dd5cd2c6388dc535e91b002a9495b572;p=thirdparty%2Ftor.git Fix: Crash on SIGSEGV if at least one worker thread cannot be launched Perform a clean shutdown in case worker threads cannot be lauched. --- diff --git a/src/app/main/main.c b/src/app/main/main.c index 6d05bd1f5e..0bb87eb08d 100644 --- a/src/app/main/main.c +++ b/src/app/main/main.c @@ -1244,7 +1244,8 @@ run_tor_main_loop(void) /* launch cpuworkers. Need to do this *after* we've read the onion key. */ /* launch them always for all tors, now that clients can solve onion PoWs. */ - cpuworker_init(); + if (cpuworker_init() == -1) + return -1; consdiffmgr_enable_background_compression(); diff --git a/src/core/mainloop/cpuworker.c b/src/core/mainloop/cpuworker.c index b12879a178..602ebda228 100644 --- a/src/core/mainloop/cpuworker.c +++ b/src/core/mainloop/cpuworker.c @@ -113,10 +113,8 @@ cpuworker_consensus_has_changed(const networkstatus_t *ns) set_max_pending_tasks(ns); } -/** Initialize the cpuworker subsystem. It is OK to call this more than once - * during Tor's lifetime. - */ -void +/** Initialize the cpuworker subsystem. */ +int cpuworker_init(void) { /* @@ -132,11 +130,18 @@ cpuworker_init(void) worker_state_free_void, NULL); + if (!threadpool) { + log_err(LD_GENERAL, "Can't create worker thread pool"); + return -1; + } + int r = threadpool_register_reply_event(threadpool, NULL); tor_assert(r == 0); set_max_pending_tasks(NULL); + + return 0; } /** Free all resources allocated by cpuworker. */ diff --git a/src/core/mainloop/cpuworker.h b/src/core/mainloop/cpuworker.h index 7f00f363fe..f976a4b379 100644 --- a/src/core/mainloop/cpuworker.h +++ b/src/core/mainloop/cpuworker.h @@ -12,7 +12,7 @@ #ifndef TOR_CPUWORKER_H #define TOR_CPUWORKER_H -void cpuworker_init(void); +int cpuworker_init(void); void cpuworker_free_all(void); void cpuworkers_rotate_keyinfo(void);