summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Joseph <george.joseph@fairview5.com>2014-02-20 21:04:28 +0000
committerGeorge Joseph <george.joseph@fairview5.com>2014-02-20 21:04:28 +0000
commit31a18c14b8cbb2e84a4d5093fd681e14fdf9ee23 (patch)
tree0d5f4ac0db909149336f5f2f9e97c4bf17c82eb5
parenta94c8562fd70bc5b317a434db36f19fd34c70f8c (diff)
pjsip_cli: Fix memory leak in ast_sip_cli_print_sorcery_objectset.
Fixed memory leaks in ast_sip_cli_print_sorcery_objectset and ast_variable_list_sort. (closes issue ASTERISK-23266) Review: http://reviewboard.asterisk.org/r/3200/ ........ Merged revisions 408520 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@408521 65c4cc65-6c06-0410-ace0-fbb531ad65f3
-rw-r--r--main/config.c14
-rw-r--r--res/res_pjsip/pjsip_cli.c7
2 files changed, 11 insertions, 10 deletions
diff --git a/main/config.c b/main/config.c
index a45f57311..8961fa9e3 100644
--- a/main/config.c
+++ b/main/config.c
@@ -596,19 +596,19 @@ inline struct ast_variable *variable_list_switch(struct ast_variable *l1, struct
struct ast_variable *ast_variable_list_sort(struct ast_variable *start)
{
- struct ast_variable *p, *q, *top;
+ struct ast_variable *p, *q;
+ struct ast_variable top;
int changed = 1;
- top = ast_calloc(1, sizeof(struct ast_variable));
- top->next = start;
+ memset(&top, 0, sizeof(top));
+ top.next = start;
if (start != NULL && start->next != NULL) {
while (changed) {
changed = 0;
- q = top;
- p = top->next;
+ q = &top;
+ p = top.next;
while (p->next != NULL) {
if (p->next != NULL && strcmp(p->name, p->next->name) > 0) {
q->next = variable_list_switch(p, p->next);
-
changed = 1;
}
q = p;
@@ -617,7 +617,7 @@ struct ast_variable *ast_variable_list_sort(struct ast_variable *start)
}
}
}
- return top->next;
+ return top.next;
}
const char *ast_config_option(struct ast_config *cfg, const char *cat, const char *var)
diff --git a/res/res_pjsip/pjsip_cli.c b/res/res_pjsip/pjsip_cli.c
index 6abd62983..6ad820a0c 100644
--- a/res/res_pjsip/pjsip_cli.c
+++ b/res/res_pjsip/pjsip_cli.c
@@ -71,9 +71,8 @@ int ast_sip_cli_print_sorcery_objectset(void *obj, void *arg, int flags)
}
}
- if (!(separator = alloca(max_name_width + max_value_width + 8))) {
- return -1;
- }
+ separator = ast_alloca(max_name_width + max_value_width + 8);
+
memset(separator, '=', max_name_width + max_value_width + 3);
separator[max_name_width + max_value_width + 3] = 0;
@@ -86,6 +85,8 @@ int ast_sip_cli_print_sorcery_objectset(void *obj, void *arg, int flags)
ast_str_append(&context->output_buffer, 0, " %-*s : %s\n", max_name_width, i->name, i->value);
}
+ ast_variables_destroy(objset);
+
return 0;
}