]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Move mutex into the global struct, don't leak on config reload (thanks Math)
authorAndrew Thompson <andrew@hijacked.us>
Fri, 19 Jun 2009 19:35:02 +0000 (19:35 +0000)
committerAndrew Thompson <andrew@hijacked.us>
Fri, 19 Jun 2009 19:35:02 +0000 (19:35 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13873 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c

index a8b04b8c4f4fb443d016086ebbf1b5700a63dfc9..d12bc0923fd0e36c28fe80118f70aadc1961a777 100644 (file)
@@ -39,7 +39,6 @@
 /* magic byte sequence */
 static unsigned char MAGIC[] = {226, 132, 177, 197, 152, 198, 142, 211, 172, 197, 158, 208, 169, 208, 135, 197, 166, 207, 154, 196, 166};
 static char *MARKER = "1";
-static switch_mutex_t *MUTEX = NULL;
 
 SWITCH_MODULE_LOAD_FUNCTION(mod_event_multicast_load);
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_event_multicast_shutdown);
@@ -63,6 +62,7 @@ static struct {
        switch_event_node_t *node;
        uint8_t ttl;
        char *psk;
+       switch_mutex_t *mutex;
 } globals;
 
 SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_address, globals.address);
@@ -82,7 +82,6 @@ static switch_status_t load_config(void)
 
        
        globals.ttl = 1;
-       globals.psk = NULL;
        globals.key_count = 0;
 
        if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
@@ -175,7 +174,7 @@ static void event_handler(switch_event_t *event)
        }
 
        if (event->event_id == SWITCH_EVENT_RELOADXML) {
-               switch_mutex_lock(MUTEX);
+               switch_mutex_lock(globals.mutex);
                switch_core_hash_destroy(&globals.event_hash);
                globals.event_hash = NULL;
                switch_core_hash_init(&globals.event_hash, module_pool);
@@ -185,10 +184,10 @@ static void event_handler(switch_event_t *event)
                } else {
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Event Multicast Reloaded\n");
                }
-               switch_mutex_unlock(MUTEX);
+               switch_mutex_unlock(globals.mutex);
        }
 
-       switch_mutex_lock(MUTEX);
+       switch_mutex_lock(globals.mutex);
        if (globals.event_list[(uint8_t) SWITCH_EVENT_ALL]) {
                send = 1;
        } else if ((globals.event_list[(uint8_t) event->event_id])) {
@@ -196,7 +195,7 @@ static void event_handler(switch_event_t *event)
                        send = 1;
                }
        }
-       switch_mutex_unlock(MUTEX);
+       switch_mutex_unlock(globals.mutex);
 
        if (send) {
                char *packet;
@@ -268,7 +267,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_event_multicast_load)
 
        memset(&globals, 0, sizeof(globals));
 
-       switch_mutex_init(&MUTEX, SWITCH_MUTEX_NESTED, pool);
+       switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, pool);
        module_pool = pool;
 
        switch_core_hash_init(&globals.event_hash, module_pool);