]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
format_cap: Fix leak on AST_VECTOR_APPEND error.
authorCorey Farrell <git@cfware.com>
Mon, 6 Nov 2017 21:07:01 +0000 (16:07 -0500)
committerCorey Farrell <git@cfware.com>
Mon, 6 Nov 2017 21:12:12 +0000 (16:12 -0500)
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

main/format_cap.c

index fc56866526a834ec01bb0d0f129b6ad39278d7ea..8a00ed64da9df51bdc8631dad3914851e317cea3 100644 (file)
@@ -177,13 +177,16 @@ static inline int format_cap_framed_init(struct format_cap_framed *framed, struc
        }
        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));
 
        return 0;