diff options
author | Florian Weimer <fweimer@redhat.com> | 2019-02-06 16:26:39 +0100 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2019-02-06 16:45:25 +0100 |
commit | 3b935595859e0232b74594c5aca6da88a31f90b3 (patch) | |
tree | 2175f653eaeed2a9afe43171062cb6acdc919bd8 /support/xdlfcn.c | |
parent | b4333340654113ce912cb0deb8856a87487cc428 (diff) | |
download | glibc-3b935595859e0232b74594c5aca6da88a31f90b3.tar glibc-3b935595859e0232b74594c5aca6da88a31f90b3.tar.gz glibc-3b935595859e0232b74594c5aca6da88a31f90b3.tar.bz2 glibc-3b935595859e0232b74594c5aca6da88a31f90b3.zip |
support: Use dlerror to detect NULL symbols in xdlsym
Diffstat (limited to 'support/xdlfcn.c')
-rw-r--r-- | support/xdlfcn.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/support/xdlfcn.c b/support/xdlfcn.c index 2f2ac76003..b2e5c21134 100644 --- a/support/xdlfcn.c +++ b/support/xdlfcn.c @@ -28,22 +28,25 @@ xdlopen (const char *filename, int flags) if (dso == NULL) FAIL_EXIT1 ("error: dlopen: %s\n", dlerror ()); - /* Clear any errors. */ - dlerror (); - return dso; } void * xdlsym (void *handle, const char *symbol) { + /* Clear any pending errors. */ + dlerror (); + void *sym = dlsym (handle, symbol); if (sym == NULL) - FAIL_EXIT1 ("error: dlsym: %s\n", dlerror ()); - - /* Clear any errors. */ - dlerror (); + { + const char *error = dlerror (); + if (error != NULL) + FAIL_EXIT1 ("error: dlsym: %s\n", error); + /* If there was no error, we found a NULL symbol. Return the + NULL value in this case. */ + } return sym; } @@ -53,7 +56,4 @@ xdlclose (void *handle) { if (dlclose (handle) != 0) FAIL_EXIT1 ("error: dlclose: %s\n", dlerror ()); - - /* Clear any errors. */ - dlerror (); } |