Commit 542950c91f for asterisk.org
commit 542950c91f1de914c122c42a534c65b0a9cc0d22
Author: Jaewoo Kim <chrysaor@naver.com>
Date: Thu Nov 26 23:58:57 2026 +0900
res_aeap: Fix crash on disconnect when the read thread errors out.
ast_aeap_disconnect() read aeap->read_thread_id after unlocking, so if
the read thread cleared it meanwhile pthread_join() was called with
AST_PTHREADT_NULL and crashed. Copy the id while still locked.
AI assistance: Claude Fable 5.1
Fixes: #2349
diff --git a/res/res_aeap/aeap.c b/res/res_aeap/aeap.c
index 9094bbb3db..86637503d3 100644
--- a/res/res_aeap/aeap.c
+++ b/res/res_aeap/aeap.c
@@ -388,9 +388,13 @@ int ast_aeap_disconnect(struct ast_aeap *aeap)
/*
* The read thread calls disconnect if an error occurs, so
* unlock the aeap before "joining" to avoid a deadlock.
+ * Copy the thread id while still locked, since the read
+ * thread's error path clears it once we unlock.
*/
+ pthread_t read_thread_id = aeap->read_thread_id;
+
ao2_unlock(aeap);
- pthread_join(aeap->read_thread_id, NULL);
+ pthread_join(read_thread_id, NULL);
ao2_lock(aeap);
aeap->read_thread_id = AST_PTHREADT_NULL;