diff options
author | Eric Anholt <eric@anholt.net> | 2014-03-27 18:54:12 -0700 |
---|---|---|
committer | Eric Anholt <eric@anholt.net> | 2014-03-27 23:17:02 -0700 |
commit | d48978c0849e48020d5326bcb35ce99b067e4b9d (patch) | |
tree | aba273b5f481850045a75a5df06b1c32460c93b5 | |
parent | 72187a29c2d1e4852dfcb9b397418ff21dae1835 (diff) | |
download | libepoxy-d48978c0849e48020d5326bcb35ce99b067e4b9d.tar.gz |
Don't leak dlerror()s while we're trying to probe libraries.
Again, no known bugs, but it seems like a bad idea.
-rw-r--r-- | src/dispatch_common.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/dispatch_common.c b/src/dispatch_common.c index c3c9245..08b8dd7 100644 --- a/src/dispatch_common.c +++ b/src/dispatch_common.c @@ -185,9 +185,13 @@ get_dlopen_handle(void **handle, const char *lib_name, bool exit_on_fail) pthread_mutex_lock(&api.mutex); if (!*handle) { *handle = dlopen(lib_name, RTLD_LAZY | RTLD_LOCAL); - if (!*handle && exit_on_fail) { - fprintf(stderr, "Couldn't open %s: %s\n", lib_name, dlerror()); - exit(1); + if (!*handle) { + if (exit_on_fail) { + fprintf(stderr, "Couldn't open %s: %s\n", lib_name, dlerror()); + exit(1); + } else { + (void)dlerror(); + } } } pthread_mutex_unlock(&api.mutex); @@ -201,6 +205,7 @@ do_dlsym(void **handle, const char *lib_name, const char *name, bool exit_on_fail) { void *result; + const char *error = ""; if (!get_dlopen_handle(handle, lib_name, exit_on_fail)) return NULL; @@ -209,9 +214,11 @@ do_dlsym(void **handle, const char *lib_name, const char *name, result = GetProcAddress(*handle, name); #else result = dlsym(*handle, name); + if (!result) + error = dlerror(); #endif if (!result && exit_on_fail) { - fprintf(stderr,"%s() not found in %s\n", name, lib_name); + fprintf(stderr,"%s() not found in %s: %s\n", name, lib_name, error); exit(1); } |