Merged revisions 81439 via svnmerge from
authorJoshua Colp <jcolp@digium.com>
Tue, 4 Sep 2007 14:25:21 +0000 (14:25 +0000)
committerJoshua Colp <jcolp@digium.com>
Tue, 4 Sep 2007 14:25:21 +0000 (14:25 +0000)
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r81439 | file | 2007-09-04 11:23:18 -0300 (Tue, 04 Sep 2007) | 6 lines

(closes issue #10632)
Reported by: jamesgolovich
Patches:
      asterisk-iaxfirmwareleak.diff.txt uploaded by jamesgolovich (license 176)
Fix memory leak when unloading chan_iax2. The firmware files were not being freed.

........

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@81440 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_iax2.c

index 7644615..163987d 100644 (file)
@@ -1886,7 +1886,7 @@ static int iax_firmware_append(struct iax_ie_data *ied, const unsigned char *dev
 }
 
 
-static void reload_firmware(void)
+static void reload_firmware(int unload)
 {
        struct iax_firmware *cur = NULL;
        DIR *fwd;
@@ -1900,20 +1900,22 @@ static void reload_firmware(void)
                cur->dead = 1;
 
        /* Now that we have marked them dead... load new ones */
-       snprintf(dir, sizeof(dir), "%s/firmware/iax", (char *)ast_config_AST_DATA_DIR);
-       fwd = opendir(dir);
-       if (fwd) {
-               while((de = readdir(fwd))) {
-                       if (de->d_name[0] != '.') {
-                               snprintf(fn, sizeof(fn), "%s/%s", dir, de->d_name);
-                               if (!try_firmware(fn)) {
-                                       ast_verb(2, "Loaded firmware '%s'\n", de->d_name);
+       if (!unload) {
+               snprintf(dir, sizeof(dir), "%s/firmware/iax", (char *)ast_config_AST_DATA_DIR);
+               fwd = opendir(dir);
+               if (fwd) {
+                       while((de = readdir(fwd))) {
+                               if (de->d_name[0] != '.') {
+                                       snprintf(fn, sizeof(fn), "%s/%s", dir, de->d_name);
+                                       if (!try_firmware(fn)) {
+                                               ast_verb(2, "Loaded firmware '%s'\n", de->d_name);
+                                       }
                                }
                        }
-               }
-               closedir(fwd);
-       } else 
-               ast_log(LOG_WARNING, "Error opening firmware directory '%s': %s\n", dir, strerror(errno));
+                       closedir(fwd);
+               } else 
+                       ast_log(LOG_WARNING, "Error opening firmware directory '%s': %s\n", dir, strerror(errno));
+       }
 
        /* Clean up leftovers */
        AST_LIST_TRAVERSE_SAFE_BEGIN(&firmwares, cur, list) {
@@ -10382,7 +10384,7 @@ static int reload_config(void)
                ao2_callback(peers, 0, iax2_poke_peer_cb, NULL);
        }
 
-       reload_firmware();
+       reload_firmware(0);
        iax_provision_reload(1);
 
        return 0;
@@ -11187,6 +11189,7 @@ static int __unload_module(void)
        delete_users();
        iax_provision_unload();
        sched_context_destroy(sched);
+       reload_firmware(1);
 
        for (x = 0; x < IAX_MAX_CALLS; x++)
                ast_mutex_destroy(&iaxsl[x]);
@@ -11317,7 +11320,7 @@ static int load_module(void)
        ao2_callback(peers, 0, iax2_poke_peer_cb, NULL);
 
 
-       reload_firmware();
+       reload_firmware(0);
        iax_provision_reload(0);
 
        return AST_MODULE_LOAD_SUCCESS;