[Asterisk-code-review] format cap: Fix leak on AST VECTOR APPEND error. (asterisk[15])

Corey Farrell asteriskteam at digium.com
Mon Nov 6 15:12:06 CST 2017


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


Change subject: format_cap: Fix leak on AST_VECTOR_APPEND error.
......................................................................

format_cap: Fix leak on AST_VECTOR_APPEND error.

format_cap_framed_init can fail on AST_VECTOR_APPEND.  This should
report failure to the caller and clean the newly allocated frame.

Change-Id: Ica0661235bf09497bf23d844ceb01f21b41a55b0
---
M main/format_cap.c
1 file changed, 6 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/32/7032/1

diff --git a/main/format_cap.c b/main/format_cap.c
index b0897c0..d71ccdb 100644
--- a/main/format_cap.c
+++ b/main/format_cap.c
@@ -160,12 +160,15 @@
 	}
 	list = AST_VECTOR_GET_ADDR(&cap->formats, ast_format_get_codec_id(format));
 
+	/* This takes the allocation reference */
+	if (AST_VECTOR_APPEND(&cap->preference_order, framed)) {
+		ao2_ref(framed, -1);
+		return -1;
+	}
+
 	/* Order doesn't matter for formats, so insert at the head for performance reasons */
 	ao2_ref(framed, +1);
 	AST_LIST_INSERT_HEAD(list, framed, entry);
-
-	/* This takes the allocation reference */
-	AST_VECTOR_APPEND(&cap->preference_order, framed);
 
 	cap->framing = MIN(cap->framing, framing ? framing : ast_format_get_default_ms(format));
 

-- 
To view, visit https://gerrit.asterisk.org/7032
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ica0661235bf09497bf23d844ceb01f21b41a55b0
Gerrit-Change-Number: 7032
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/9c433df1/attachment-0001.html>


More information about the asterisk-code-review mailing list