Merge pull request #238 from camelid/dlopen

Handle NULL return value from dlopen
This commit is contained in:
Emery Berger 2024-07-07 16:17:31 -04:00 committed by GitHub
commit 985c15f533
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,6 +6,7 @@
*/
#include "real.h"
#include "ccutil/log.h"
#include <dlfcn.h>
@ -37,6 +38,7 @@ static void* pthread_handle = NULL; //< The `dlopen` handle to libpthread
static void* get_pthread_handle() {
if(pthread_handle == NULL && !__atomic_exchange_n(&in_dlopen, true, __ATOMIC_ACQ_REL)) {
pthread_handle = dlopen("libpthread.so.0", RTLD_NOW | RTLD_GLOBAL);
REQUIRE(pthread_handle != NULL) << dlerror();
__atomic_store_n(&in_dlopen, false, __ATOMIC_RELEASE);
}