diff --git a/src/os/portable/os-impl-posix-dl-loader.c b/src/os/portable/os-impl-posix-dl-loader.c index 55aa9ac3c..ff8c3e513 100644 --- a/src/os/portable/os-impl-posix-dl-loader.c +++ b/src/os/portable/os-impl-posix-dl-loader.c @@ -90,20 +90,23 @@ int32 OS_ModuleLoad_Impl(uint32 module_id, const char *translated_path) *-----------------------------------------------------------------*/ int32 OS_ModuleUnload_Impl(uint32 module_id) { - int32 status = OS_ERROR; + int32 status = OS_SUCCESS; /* ** Attempt to close/unload the module */ - dlerror(); - if (dlclose(OS_impl_module_table[module_id].dl_handle) == 0) - { - OS_impl_module_table[module_id].dl_handle = NULL; - status = OS_SUCCESS; - } - else + if (OS_impl_module_table[module_id].dl_handle != NULL) { - OS_DEBUG("Error unloading shared library: %s\n", dlerror()); + dlerror(); + if (dlclose(OS_impl_module_table[module_id].dl_handle) == 0) + { + OS_impl_module_table[module_id].dl_handle = NULL; + } + else + { + OS_DEBUG("Error unloading shared library: %s\n", dlerror()); + status = OS_ERROR; + } } return status; diff --git a/src/os/rtems/src/os-impl-loader.c b/src/os/rtems/src/os-impl-loader.c index 89fbbedce..2fd7412c6 100644 --- a/src/os/rtems/src/os-impl-loader.c +++ b/src/os/rtems/src/os-impl-loader.c @@ -179,20 +179,23 @@ int32 OS_ModuleLoad_Impl(uint32 module_id, const char *translated_path) *-----------------------------------------------------------------*/ int32 OS_ModuleUnload_Impl(uint32 module_id) { - int32 status = OS_ERROR; + int32 status = OS_SUCCESS; /* ** Attempt to close/unload the module */ - dlerror(); - if (dlclose(OS_impl_module_table[module_id].dl_handle) == 0) - { - OS_impl_module_table[module_id].dl_handle = NULL; - status = OS_SUCCESS; - } - else + if (OS_impl_module_table[module_id].dl_handle != NULL) { - OS_DEBUG("Error unloading shared library: %s\n", dlerror()); + dlerror(); + if (dlclose(OS_impl_module_table[module_id].dl_handle) == 0) + { + OS_impl_module_table[module_id].dl_handle = NULL; + } + else + { + OS_DEBUG("Error unloading shared library: %s\n", dlerror()); + status = OS_ERROR; + } } return status;