src/dynapi/SDL_dynapi.c
changeset 9305 0c66e0df64f6
parent 8820 0e935d5b193a
child 9619 b94b6d0bff0f
     1.1 --- a/src/dynapi/SDL_dynapi.c	Wed Dec 31 21:00:32 2014 +0100
     1.2 +++ b/src/dynapi/SDL_dynapi.c	Mon Jan 05 01:07:36 2015 -0500
     1.3 @@ -206,7 +206,14 @@
     1.4  static SDL_INLINE void *get_sdlapi_entry(const char *fname, const char *sym)
     1.5  {
     1.6      HANDLE lib = LoadLibraryA(fname);
     1.7 -    return lib ? GetProcAddress(lib, sym) : NULL;
     1.8 +    void *retval = NULL;
     1.9 +    if (lib) {
    1.10 +        retval = GetProcAddress(lib, sym);
    1.11 +        if (retval == NULL) {
    1.12 +            FreeLibrary(lib);
    1.13 +        }
    1.14 +    }
    1.15 +    return retval;
    1.16  }
    1.17  
    1.18  #elif defined(__HAIKU__)
    1.19 @@ -215,8 +222,11 @@
    1.20  {
    1.21      image_id lib = load_add_on(fname);
    1.22      void *retval = NULL;
    1.23 -    if ((lib < 0) || (get_image_symbol(lib, sym, B_SYMBOL_TYPE_TEXT, &retval) != B_NO_ERROR)) {
    1.24 -        retval = NULL;
    1.25 +    if (lib >= 0) {
    1.26 +        if (get_image_symbol(lib, sym, B_SYMBOL_TYPE_TEXT, &retval) != B_NO_ERROR) {
    1.27 +            unload_add_on(lib);
    1.28 +            retval = NULL;
    1.29 +        }
    1.30      }
    1.31      return retval;
    1.32  }
    1.33 @@ -225,7 +235,14 @@
    1.34  static SDL_INLINE void *get_sdlapi_entry(const char *fname, const char *sym)
    1.35  {
    1.36      void *lib = dlopen(fname, RTLD_NOW | RTLD_LOCAL);
    1.37 -    return lib ? dlsym(lib, sym) : NULL;
    1.38 +    void *retval = NULL;
    1.39 +    if (lib != NULL) {
    1.40 +        retval = dlsym(lib, sym);
    1.41 +        if (retval == NULL) {
    1.42 +            dlclose(lib);
    1.43 +        }
    1.44 +    }
    1.45 +    return retval;
    1.46  }
    1.47  #else
    1.48  #error Please define your platform.