Skip to content

Commit

Permalink
Fix #637, fix OS_ModuleUnload for static modules
Browse files Browse the repository at this point in the history
Ensure that the handle is not NULL before invoking dlclose().
In particular the handle will be NULL for static modules.
  • Loading branch information
jphickey committed Oct 30, 2020
1 parent 5a8f0af commit 902f09a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
21 changes: 12 additions & 9 deletions src/os/portable/os-impl-posix-dl-loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 12 additions & 9 deletions src/os/rtems/src/os-impl-loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 902f09a

Please sign in to comment.