[asterisk-commits] seanbright: branch 1.4 r241015 - /branches/1.4/main/config.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jan 18 13:54:24 CST 2010


Author: seanbright
Date: Mon Jan 18 13:54:19 2010
New Revision: 241015

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=241015
Log:
Plug a memory leak when reading configs with their comments.

While reading through configuration files with the intent of returning their
full contents (comments specifically) we allocated some memory and then forgot
to free it.  This doesn't fix 16554 but clears up a leak I had in the lab.

(issue #16554)
Reported by: mav3rick
Patches:
      issue16554_20100118.patch uploaded by seanbright (license 71)
Tested by: seanbright

Modified:
    branches/1.4/main/config.c

Modified: branches/1.4/main/config.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.4/main/config.c?view=diff&rev=241015&r1=241014&r2=241015
==============================================================================
--- branches/1.4/main/config.c (original)
+++ branches/1.4/main/config.c Mon Jan 18 13:54:19 2010
@@ -183,6 +183,8 @@
 	int max_include_level;
 };
 
+static void ast_destroy_comment(struct ast_comment **comment);
+
 struct ast_variable *ast_variable_new(const char *name, const char *value) 
 {
 	struct ast_variable *variable;
@@ -218,6 +220,8 @@
 	while(v) {
 		vn = v;
 		v = v->next;
+		ast_destroy_comment(&vn->precomments);
+		ast_destroy_comment(&vn->sameline);
 		free(vn);
 	}
 }
@@ -344,19 +348,22 @@
 	config->current = category;
 }
 
-static void ast_destroy_comments(struct ast_category *cat)
+static void ast_destroy_comment(struct ast_comment **comment)
 {
 	struct ast_comment *n, *p;
-	for (p=cat->precomments; p; p=n) {
+
+	for (p = *comment; p; p = n) {
 		n = p->next;
 		free(p);
 	}
-	for (p=cat->sameline; p; p=n) {
-		n = p->next;
-		free(p);
-	}
-	cat->precomments = NULL;
-	cat->sameline = NULL;
+
+	*comment = NULL;
+}
+
+static void ast_destroy_comments(struct ast_category *cat)
+{
+	ast_destroy_comment(&cat->precomments);
+	ast_destroy_comment(&cat->sameline);
 }
 
 static void ast_destroy_template_list(struct ast_category *cat)




More information about the asterisk-commits mailing list