Merge pull request #36 from dlfcn-win32/fix-dlerror Fix bug in dlerror second consecutive call
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
diff --git a/dlfcn.c b/dlfcn.c
index 4367bd7..a91e963 100644
--- a/dlfcn.c
+++ b/dlfcn.c
@@ -431,6 +431,12 @@ end:
char *dlerror( void )
{
char *error_pointer = dlerror_buffer;
+
+ /* If this is the second consecutive call to dlerror, return NULL */
+ if (current_error == NULL)
+ {
+ return NULL;
+ }
#ifdef UNICODE
errno_t err = 0;
diff --git a/test.c b/test.c
index 14523ad..ba440da 100644
--- a/test.c
+++ b/test.c
@@ -304,6 +304,21 @@ int main()
error = dlerror( );
printf( "SUCCESS\tCould not get nonexistent symbol from global handle: %s\n",
error ? error : "" );
+
+ /* Test that the second call to dlerror() returns null as in the specs
+ See https://github.com/dlfcn-win32/dlfcn-win32/issues/34 */
+ error = dlerror( );
+ if( error == NULL )
+ {
+ printf( "SUCCESS\tSecond consecutive call to dlerror returned NULL\n");
+ }
+ else
+ {
+ printf( "ERROR\tSecond consecutive call to dlerror returned a non-NULL pointer: %p\n", error );
+ CLOSE_LIB;
+ CLOSE_GLOBAL;
+ RETURN_ERROR;
+ }
}
function = dlsym(global, "fwrite");