summaryrefslogtreecommitdiff
path: root/main/config.c
diff options
context:
space:
mode:
authorSean Bright <sean@malleable.com>2010-01-18 19:57:52 +0000
committerSean Bright <sean@malleable.com>2010-01-18 19:57:52 +0000
commitbb03a2f7d92dea7857323fd2edf1ee028f84922f (patch)
treea0e7129acf7b3762c64cfd93056472c365331386 /main/config.c
parentf6b5cf960f2856ee4d9a7144e37b89542c0ef85c (diff)
Merged revisions 241015 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r241015 | seanbright | 2010-01-18 14:54:19 -0500 (Mon, 18 Jan 2010) | 12 lines 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 ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@241016 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/config.c')
-rw-r--r--main/config.c40
1 files changed, 18 insertions, 22 deletions
diff --git a/main/config.c b/main/config.c
index 3d4982a88..c8e26ed4e 100644
--- a/main/config.c
+++ b/main/config.c
@@ -382,6 +382,18 @@ void ast_variable_insert(struct ast_category *category, struct ast_variable *var
}
}
+static void ast_comment_destroy(struct ast_comment **comment)
+{
+ struct ast_comment *n, *p;
+
+ for (p = *comment; p; p = n) {
+ n = p->next;
+ ast_free(p);
+ }
+
+ *comment = NULL;
+}
+
void ast_variables_destroy(struct ast_variable *v)
{
struct ast_variable *vn;
@@ -389,6 +401,9 @@ void ast_variables_destroy(struct ast_variable *v)
while (v) {
vn = v;
v = v->next;
+ ast_comment_destroy(&vn->precomments);
+ ast_comment_destroy(&vn->sameline);
+ ast_comment_destroy(&vn->trailing);
ast_free(vn);
}
}
@@ -535,27 +550,6 @@ void ast_category_insert(struct ast_config *config, struct ast_category *cat, co
}
}
-static void ast_destroy_comments(struct ast_category *cat)
-{
- struct ast_comment *n, *p;
-
- for (p=cat->precomments; p; p=n) {
- n = p->next;
- free(p);
- }
- for (p=cat->sameline; p; p=n) {
- n = p->next;
- free(p);
- }
- for (p=cat->trailing; p; p=n) {
- n = p->next;
- free(p);
- }
- cat->precomments = NULL;
- cat->sameline = NULL;
- cat->trailing = NULL;
-}
-
static void ast_destroy_template_list(struct ast_category *cat)
{
struct ast_category_template_instance *x;
@@ -571,7 +565,9 @@ void ast_category_destroy(struct ast_category *cat)
free(cat->file);
cat->file = 0;
}
- ast_destroy_comments(cat);
+ ast_comment_destroy(&cat->precomments);
+ ast_comment_destroy(&cat->sameline);
+ ast_comment_destroy(&cat->trailing);
ast_destroy_template_list(cat);
ast_free(cat);
}