Commit c989a611 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Use vlc_module_destroy() instead of DeleteModule() where possible

This avoids going through the linked list of modules. This is fine so
long as the module structure is indeed not in the list.
parent d4b0d0c8
...@@ -83,8 +83,14 @@ module_t *vlc_module_create (module_t *parent) ...@@ -83,8 +83,14 @@ module_t *vlc_module_create (module_t *parent)
return module; return module;
} }
/**
* Destroys a plug-in.
* @warning If the plug-in is loaded in memory, the handle will be leaked.
*/
void vlc_module_destroy (module_t *module) void vlc_module_destroy (module_t *module)
{ {
assert (!module->b_loaded || !module->b_unloadable);
for (module_t *m = module->submodule, *next; m != NULL; m = next) for (module_t *m = module->submodule, *next; m != NULL; m = next)
{ {
next = m->next; next = m->next;
......
...@@ -511,17 +511,17 @@ found_shortcut: ...@@ -511,17 +511,17 @@ found_shortcut:
if (!p_real->b_loaded) if (!p_real->b_loaded)
{ {
assert (p_real->psz_filename != NULL); module_t *uncache; /* Map module in process */
module_t *p_new_module = assert (p_real->psz_filename != NULL);
module_InitDynamic (p_this, p_real->psz_filename, false); uncache = module_InitDynamic (p_this, p_real->psz_filename, false);
if( p_new_module == NULL ) if (uncache == NULL)
{ /* Corrupted module */ { /* Corrupted module */
msg_Err( p_this, "possibly corrupt module cache" ); msg_Err( p_this, "possibly corrupt module cache" );
continue; continue;
} }
CacheMerge( p_this, p_real, p_new_module ); CacheMerge (p_this, p_real, uncache);
DeleteModule (&modules.head, p_new_module); vlc_module_destroy (uncache);
} }
#endif #endif
p_this->b_force = p_list[i].b_force; p_this->b_force = p_list[i].b_force;
...@@ -834,10 +834,11 @@ static void AllocatePluginPath (vlc_object_t *p_this, const char *path, ...@@ -834,10 +834,11 @@ static void AllocatePluginPath (vlc_object_t *p_this, const char *path,
switch( mode ) switch( mode )
{ {
case CACHE_USE: case CACHE_USE:
/* Discard unmatched cache entries */
for( size_t i = 0; i < count; i++ ) for( size_t i = 0; i < count; i++ )
{ {
if (cache[i].p_module != NULL) if (cache[i].p_module != NULL)
DeleteModule (&modules.head, cache[i].p_module); vlc_module_destroy (cache[i].p_module);
free (cache[i].path); free (cache[i].path);
} }
free( cache ); free( cache );
...@@ -939,8 +940,7 @@ static int AllocatePluginFile( vlc_object_t * p_this, module_bank_t *p_bank, ...@@ -939,8 +940,7 @@ static int AllocatePluginFile( vlc_object_t * p_this, module_bank_t *p_bank,
if( p_module->p_config[i].i_action ) if( p_module->p_config[i].i_action )
{ {
/* !unloadable not allowed for plugins with callbacks */ /* !unloadable not allowed for plugins with callbacks */
assert( !p_module->b_loaded ); vlc_module_destroy (p_module);
DeleteModule (&modules.head, p_module);
p_module = module_InitDynamic (p_this, path, false); p_module = module_InitDynamic (p_this, path, false);
break; break;
} }
...@@ -1051,7 +1051,10 @@ static void DeleteModule (module_t **head, module_t *p_module) ...@@ -1051,7 +1051,10 @@ static void DeleteModule (module_t **head, module_t *p_module)
/* We free the structures that we strdup()ed in Allocate*Module(). */ /* We free the structures that we strdup()ed in Allocate*Module(). */
#ifdef HAVE_DYNAMIC_PLUGINS #ifdef HAVE_DYNAMIC_PLUGINS
if (p_module->b_loaded && p_module->b_unloadable) if (p_module->b_loaded && p_module->b_unloadable)
{
module_Unload (p_module->handle); module_Unload (p_module->handle);
p_module->b_loaded = false;
}
#endif #endif
vlc_module_destroy (p_module); vlc_module_destroy (p_module);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment