[Asterisk-code-review] res pjsip history: Fix multiple leaks on vector append failure. (asterisk[13])
Joshua Colp
asteriskteam at digium.com
Thu Nov 9 03:44:21 CST 2017
Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/7100 )
Change subject: res_pjsip_history: Fix multiple leaks on vector append failure.
......................................................................
res_pjsip_history: Fix multiple leaks on vector append failure.
Change-Id: I41e8d5183ace284095cc721f3b1fb32ade3f940f
---
M res/res_pjsip_history.c
1 file changed, 23 insertions(+), 7 deletions(-)
Approvals:
Richard Mudgett: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, approved; Approved for Submit
diff --git a/res/res_pjsip_history.c b/res/res_pjsip_history.c
index 0b50f68..bcc4877 100644
--- a/res/res_pjsip_history.c
+++ b/res/res_pjsip_history.c
@@ -707,10 +707,13 @@
pj_sockaddr_cp(&entry->dst, &tdata->tp_info.dst_addr);
ast_mutex_lock(&history_lock);
- AST_VECTOR_APPEND(&vector_history, entry);
+ if (AST_VECTOR_APPEND(&vector_history, entry)) {
+ ao2_ref(entry, -1);
+ entry = NULL;
+ }
ast_mutex_unlock(&history_lock);
- if (log_level != -1) {
+ if (log_level != -1 && entry) {
char line[256];
sprint_list_entry(entry, line, sizeof(line));
@@ -747,10 +750,13 @@
}
ast_mutex_lock(&history_lock);
- AST_VECTOR_APPEND(&vector_history, entry);
+ if (AST_VECTOR_APPEND(&vector_history, entry)) {
+ ao2_ref(entry, -1);
+ entry = NULL;
+ }
ast_mutex_unlock(&history_lock);
- if (log_level != -1) {
+ if (log_level != -1 && entry) {
char line[256];
sprint_list_entry(entry, line, sizeof(line));
@@ -961,7 +967,9 @@
/* If this is not an operator, push it to the stack */
if (!it_queue->op) {
- AST_VECTOR_APPEND(&stack, it_queue);
+ if (AST_VECTOR_APPEND(&stack, it_queue)) {
+ goto error;
+ }
continue;
}
@@ -1037,7 +1045,11 @@
if (!result) {
goto error;
}
- AST_VECTOR_APPEND(&stack, result);
+ if (AST_VECTOR_APPEND(&stack, result)) {
+ expression_token_free(result);
+
+ goto error;
+ }
}
/*
@@ -1058,6 +1070,7 @@
}
result = final->result;
ast_free(final);
+ AST_VECTOR_FREE(&stack);
return result;
@@ -1100,6 +1113,7 @@
queue = build_expression_queue(a);
if (!queue) {
+ AST_VECTOR_PTR_FREE(output);
return NULL;
}
@@ -1120,7 +1134,9 @@
} else if (!res) {
continue;
} else {
- AST_VECTOR_APPEND(output, ao2_bump(entry));
+ if (AST_VECTOR_APPEND(output, ao2_bump(entry))) {
+ ao2_cleanup(entry);
+ }
}
}
ast_mutex_unlock(&history_lock);
--
To view, visit https://gerrit.asterisk.org/7100
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: merged
Gerrit-Change-Id: I41e8d5183ace284095cc721f3b1fb32ade3f940f
Gerrit-Change-Number: 7100
Gerrit-PatchSet: 2
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171109/4ebced82/attachment.html>
More information about the asterisk-code-review
mailing list