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

Joshua Colp asteriskteam at digium.com
Tue Nov 7 14:32:16 CST 2017


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

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(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve; Approved for Submit
  George Joseph: Looks good to me, but someone else must approve
  Richard Mudgett: Looks good to me, approved



diff --git a/main/format_cap.c b/main/format_cap.c
index fc56866..8a00ed6 100644
--- a/main/format_cap.c
+++ b/main/format_cap.c
@@ -177,12 +177,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/7033
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: merged
Gerrit-Change-Id: Ica0661235bf09497bf23d844ceb01f21b41a55b0
Gerrit-Change-Number: 7033
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.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/20171107/f3a74889/attachment.html>


More information about the asterisk-code-review mailing list