[svn-commits] rmudgett: branch 1.4 r222797 - /branches/1.4/channels/misdn_config.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Oct 8 11:33:10 CDT 2009


Author: rmudgett
Date: Thu Oct  8 11:33:06 2009
New Revision: 222797

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=222797
Log:
Fix memory leak if chan_misdn config parameter is repeated.

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

Modified:
    branches/1.4/channels/misdn_config.c

Modified: branches/1.4/channels/misdn_config.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.4/channels/misdn_config.c?view=diff&rev=222797&r1=222796&r2=222797
==============================================================================
--- branches/1.4/channels/misdn_config.c (original)
+++ branches/1.4/channels/misdn_config.c Thu Oct  8 11:33:06 2009
@@ -878,6 +878,9 @@
 
 	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 @@
 		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 @@
 		}
 		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;
 	}




More information about the svn-commits mailing list