From 72187a29c2d1e4852dfcb9b397418ff21dae1835 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Thu, 27 Mar 2014 18:53:10 -0700 Subject: [PATCH] Don't dlsym() if we failed to dlopen(). No reported bugs I'm fixing here, just cleanup. --- src/dispatch_common.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/dispatch_common.c b/src/dispatch_common.c index bc2b827..c3c9245 100644 --- a/src/dispatch_common.c +++ b/src/dispatch_common.c @@ -167,11 +167,11 @@ library_init(void) library_initialized = true; } -static void +static bool get_dlopen_handle(void **handle, const char *lib_name, bool exit_on_fail) { if (*handle) - return; + return true; if (!library_initialized) { fprintf(stderr, @@ -192,6 +192,8 @@ get_dlopen_handle(void **handle, const char *lib_name, bool exit_on_fail) } pthread_mutex_unlock(&api.mutex); #endif + + return *handle != NULL; } static void * @@ -200,7 +202,8 @@ do_dlsym(void **handle, const char *lib_name, const char *name, { void *result; - get_dlopen_handle(handle, lib_name, exit_on_fail); + if (!get_dlopen_handle(handle, lib_name, exit_on_fail)) + return NULL; #ifdef _WIN32 result = GetProcAddress(*handle, name);