]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Fix memory leak if chan_misdn config parameter is repeated.
authorRichard Mudgett <rmudgett@digium.com>
Thu, 8 Oct 2009 16:33:06 +0000 (16:33 +0000)
committerRichard Mudgett <rmudgett@digium.com>
Thu, 8 Oct 2009 16:33:06 +0000 (16:33 +0000)
Memory leak when the same config option is set more than once in an
misdn.conf section.  Why must this be considered?  Templates!  Defining a
template with default port options and later adding to or overriding some
of them.

Patches:
      memleak-misdn.patch

JIRA ABE-1998

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

channels/misdn_config.c

index 9d947f726a588c485a179abbc0637ea75f2d2ccd..fce0915bc284e5a78e54f1a2d5809b0d7e882bba 100644 (file)
@@ -878,6 +878,9 @@ static int _parse (union misdn_cfg_pt *dest, char *value, enum misdn_cfg_type ty
 
        switch (type) {
        case MISDN_CTYPE_STR:
+               if (dest->str) {
+                       free(dest->str);
+               }
                if ((len = strlen(value))) {
                        dest->str = (char *)malloc((len + 1) * sizeof(char));
                        strncpy(dest->str, value, len);
@@ -895,18 +898,24 @@ static int _parse (union misdn_cfg_pt *dest, char *value, enum misdn_cfg_type ty
                else
                        pat="%30d";
                if (sscanf(value, pat, &tmp)) {
-                       dest->num = (int *)malloc(sizeof(int));
+                       if (!dest->num) {
+                               dest->num = (int *)malloc(sizeof(int));
+                       }
                        memcpy(dest->num, &tmp, sizeof(int));
                } else
                        re = -1;
        }
                break;
        case MISDN_CTYPE_BOOL:
-               dest->num = (int *)malloc(sizeof(int));
+               if (!dest->num) {
+                       dest->num = (int *)malloc(sizeof(int));
+               }
                *(dest->num) = (ast_true(value) ? 1 : 0);
                break;
        case MISDN_CTYPE_BOOLINT:
-               dest->num = (int *)malloc(sizeof(int));
+               if (!dest->num) {
+                       dest->num = (int *)malloc(sizeof(int));
+               }
                if (sscanf(value, "%30d", &tmp)) {
                        memcpy(dest->num, &tmp, sizeof(int));
                } else {
@@ -925,7 +934,9 @@ static int _parse (union misdn_cfg_pt *dest, char *value, enum misdn_cfg_type ty
                }
                break;
        case MISDN_CTYPE_ASTGROUP:
-               dest->grp = (ast_group_t *)malloc(sizeof(ast_group_t));
+               if (!dest->grp) {
+                       dest->grp = (ast_group_t *)malloc(sizeof(ast_group_t));
+               }
                *(dest->grp) = ast_get_group(value);
                break;
        }