[vlc-commits] modules: fix race in module_Map()
Rémi Denis-Courmont
git at videolan.org
Thu Oct 2 19:50:39 CEST 2014
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Oct 2 20:44:33 2014 +0300| [318c24cbdbdd21ebfb3678c68853e3e9726560c0] | committer: Rémi Denis-Courmont
modules: fix race in module_Map()
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=318c24cbdbdd21ebfb3678c68853e3e9726560c0
---
src/modules/bank.c | 34 +++++++++++++++++++++-------------
1 file changed, 21 insertions(+), 13 deletions(-)
diff --git a/src/modules/bank.c b/src/modules/bank.c
index 6655f00..f4fba50 100644
--- a/src/modules/bank.c
+++ b/src/modules/bank.c
@@ -639,23 +639,31 @@ static module_t *module_InitStatic (vlc_plugin_cb entry)
*/
int module_Map (vlc_object_t *obj, module_t *module)
{
+ static vlc_mutex_t lock = VLC_STATIC_MUTEX;
+
if (module->parent != NULL)
module = module->parent;
-#warning FIXME: race condition!
- if (module->b_loaded)
- return 0;
- assert (module->psz_filename != NULL);
+ vlc_mutex_lock(&lock);
+ if (!module->b_loaded)
+ {
+ module_t *uncache;
+ assert (module->psz_filename != NULL);
#ifdef HAVE_DYNAMIC_PLUGINS
- module_t *uncache = module_InitDynamic (obj, module->psz_filename, false);
- if (uncache != NULL)
- {
- CacheMerge (obj, module, uncache);
- vlc_module_destroy (uncache);
- return 0;
- }
+ uncache = module_InitDynamic (obj, module->psz_filename, false);
+ if (uncache != NULL)
+ {
+ CacheMerge (obj, module, uncache);
+ vlc_module_destroy (uncache);
+ }
+ else
#endif
- msg_Err (obj, "corrupt module: %s", module->psz_filename);
- return -1;
+ {
+ msg_Err (obj, "corrupt module: %s", module->psz_filename);
+ module = NULL;
+ }
+ }
+ vlc_mutex_unlock(&lock);
+ return -(module == NULL);
}
More information about the vlc-commits
mailing list