]> code.delx.au - pulseaudio/commitdiff
module: Assign the index before calling init()
authorTanu Kaskinen <tanu.kaskinen@intel.com>
Mon, 29 Apr 2013 13:46:13 +0000 (16:46 +0300)
committerArun Raghavan <arun.raghavan@collabora.co.uk>
Mon, 3 Jun 2013 19:08:41 +0000 (00:38 +0530)
Any code that runs inside the init() callback sees an invalid module
index. Sometimes init() does things that cause hooks to be fired. This
means that any code that uses hooks may see an invalid module index.
Fix this by assigning the module index before init() is called.

There are no known issues in the upstream code base where an invalid
module index would be used, but an out-of-tree module
(module-murphy-ivi) had a problem with this.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=63923
src/pulsecore/module.c

index 6f276bb72eb8e24e6b5b5ea583da0df8f87db761..f30a3ce93a8b27dfb089e506b855a5dfd26a0cc1 100644 (file)
@@ -113,14 +113,14 @@ pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) {
     m->core = c;
     m->unload_requested = FALSE;
 
+    pa_assert_se(pa_idxset_put(c->modules, m, &m->index) >= 0);
+    pa_assert(m->index != PA_IDXSET_INVALID);
+
     if (m->init(m) < 0) {
         pa_log_error("Failed to load module \"%s\" (argument: \"%s\"): initialization failed.", name, argument ? argument : "");
         goto fail;
     }
 
-    pa_assert_se(pa_idxset_put(c->modules, m, &m->index) >= 0);
-    pa_assert(m->index != PA_IDXSET_INVALID);
-
     pa_log_info("Loaded \"%s\" (index: #%u; argument: \"%s\").", m->name, m->index, m->argument ? m->argument : "");
 
     pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_MODULE|PA_SUBSCRIPTION_EVENT_NEW, m->index);
@@ -144,6 +144,9 @@ pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) {
 fail:
 
     if (m) {
+        if (m->index != PA_IDXSET_INVALID)
+            pa_idxset_remove_by_index(c->modules, m->index);
+
         if (m->proplist)
             pa_proplist_free(m->proplist);