[Asterisk-code-review] res pjsip history: Fix multiple leaks on vector append failure. (asterisk[15])

Joshua Colp asteriskteam at digium.com
Thu Nov 9 03:44:31 CST 2017


Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/7099 )

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 4e7dbd0..ed374d6 100644
--- a/res/res_pjsip_history.c
+++ b/res/res_pjsip_history.c
@@ -705,10 +705,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));
@@ -745,10 +748,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));
@@ -959,7 +965,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;
 		}
 
@@ -1035,7 +1043,11 @@
 		if (!result) {
 			goto error;
 		}
-		AST_VECTOR_APPEND(&stack, result);
+		if (AST_VECTOR_APPEND(&stack, result)) {
+			expression_token_free(result);
+
+			goto error;
+		}
 	}
 
 	/*
@@ -1056,6 +1068,7 @@
 	}
 	result = final->result;
 	ast_free(final);
+	AST_VECTOR_FREE(&stack);
 
 	return result;
 
@@ -1098,6 +1111,7 @@
 
 	queue = build_expression_queue(a);
 	if (!queue) {
+		AST_VECTOR_PTR_FREE(output);
 		return NULL;
 	}
 
@@ -1118,7 +1132,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/7099
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: merged
Gerrit-Change-Id: I41e8d5183ace284095cc721f3b1fb32ade3f940f
Gerrit-Change-Number: 7099
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/816142ed/attachment.html>


More information about the asterisk-code-review mailing list