From a9c33d152e71d228d692b870ddf88ea1c6af3dfc Mon Sep 17 00:00:00 2001 From: David Reid Date: Sat, 12 Dec 2020 12:14:14 +1000 Subject: [PATCH] Fix a crash when initializing a POSIX thread. Public issue https://github.com/mackron/miniaudio/issues/247 --- miniaudio.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/miniaudio.h b/miniaudio.h index edb2fabb..0f95d0a1 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -10003,8 +10003,6 @@ static ma_result ma_thread_create__posix(ma_thread* pThread, ma_thread_priority } } } - - pthread_attr_destroy(&attr); } #else /* It's the emscripten build. We'll have a few unused parameters. */ @@ -10013,6 +10011,12 @@ static ma_result ma_thread_create__posix(ma_thread* pThread, ma_thread_priority #endif result = pthread_create(pThread, pAttr, entryProc, pData); + + /* The thread attributes object is no longer required. */ + if (pAttr != NULL) { + pthread_attr_destroy(pAttr); + } + if (result != 0) { return ma_result_from_errno(result); }