From feb267e61184887bb0cd1da09e62762ef0bbe9a4 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sun, 18 Dec 2011 16:49:37 +0100 Subject: [PATCH] unix: it's legal for dlsym() to return NULL A symbol name can map to NULL. Check dlerror() to see if a real error happened. --- include/uv.h | 3 ++- src/unix/dl.c | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/include/uv.h b/include/uv.h index e8b70b18..a2007087 100644 --- a/include/uv.h +++ b/include/uv.h @@ -1250,7 +1250,8 @@ UV_EXTERN uv_err_t uv_dlopen(const char* filename, uv_lib_t* library); UV_EXTERN uv_err_t uv_dlclose(uv_lib_t library); /* - * Retrieves a data pointer from a dynamic library. + * Retrieves a data pointer from a dynamic library. It is legal for a symbol to + * map to NULL. */ UV_EXTERN uv_err_t uv_dlsym(uv_lib_t library, const char* name, void** ptr); diff --git a/src/unix/dl.c b/src/unix/dl.c index 01f51d3e..41c244d7 100644 --- a/src/unix/dl.c +++ b/src/unix/dl.c @@ -53,8 +53,14 @@ uv_err_t uv_dlclose(uv_lib_t library) { uv_err_t uv_dlsym(uv_lib_t library, const char* name, void** ptr) { - void* address = dlsym(library, name); - if (address == NULL) { + void* address; + + /* Reset error status. */ + dlerror(); + + address = dlsym(library, name); + + if (dlerror()) { return uv_inval_; }