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

Corey Farrell asteriskteam at digium.com
Mon Nov 6 18:13:40 CST 2017


Corey Farrell has uploaded this change for review. ( https://gerrit.asterisk.org/7086


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, 18 insertions(+), 5 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/86/7086/1

diff --git a/res/res_pjsip_history.c b/res/res_pjsip_history.c
index 4e7dbd0..0627c60 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,7 +748,10 @@
 	}
 
 	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) {
@@ -959,6 +965,7 @@
 
 		/* If this is not an operator, push it to the stack */
 		if (!it_queue->op) {
+			/* BUGBUG: possible leak on failure? */
 			AST_VECTOR_APPEND(&stack, it_queue);
 			continue;
 		}
@@ -1035,7 +1042,11 @@
 		if (!result) {
 			goto error;
 		}
-		AST_VECTOR_APPEND(&stack, result);
+		if (AST_VECTOR_APPEND(&stack, result)) {
+			expression_token_free(result);
+
+			goto error;
+		}
 	}
 
 	/*
@@ -1118,7 +1129,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/7086
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I41e8d5183ace284095cc721f3b1fb32ade3f940f
Gerrit-Change-Number: 7086
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171106/13542f8c/attachment.html>


More information about the asterisk-code-review mailing list