]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
func_jitterbuffer: fix frame leaks.
authorCorey Farrell <git@cfware.com>
Sun, 2 Nov 2014 07:35:36 +0000 (07:35 +0000)
committerCorey Farrell <git@cfware.com>
Sun, 2 Nov 2014 07:35:36 +0000 (07:35 +0000)
Fix code paths where it is possible for frames to leak.
Fix uninitialized variable in jb_get_fixed and jb_get_adaptive.

ASTERISK-22409 #related
Reported by: Corey Farrell
Review: https://reviewboard.asterisk.org/r/4128/

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/11@427019 65c4cc65-6c06-0410-ace0-fbb531ad65f3

funcs/func_jitterbuffer.c
main/abstract_jb.c

index 96c81ec95fc90947f8261d051ae02a6cda3e65d9..21070e0c159cb92bba119b6f96bc4eee0d85b472 100644 (file)
@@ -254,8 +254,14 @@ static struct ast_frame *hook_event_cb(struct ast_channel *chan, struct ast_fram
                } else {
                        res = framedata->jb_impl->put(framedata->jb_obj, jbframe, now);
                }
+
                if (res == AST_JB_IMPL_OK) {
+                       if (jbframe != frame) {
+                               ast_frfree(frame);
+                       }
                        frame = &ast_null_frame;
+               } else if (jbframe != frame) {
+                       ast_frfree(jbframe);
                }
                putframe = 1;
        }
@@ -282,6 +288,8 @@ static struct ast_frame *hook_event_cb(struct ast_channel *chan, struct ast_fram
                        }
                }
 
+               ast_frfree(frame);
+               frame = &ast_null_frame;
                res = framedata->jb_impl->get(framedata->jb_obj, &frame, now, framedata->timer_interval);
                switch (res) {
                case AST_JB_IMPL_OK:
@@ -294,6 +302,7 @@ static struct ast_frame *hook_event_cb(struct ast_channel *chan, struct ast_fram
                case AST_JB_IMPL_INTERP:
                        if (framedata->last_format.id) {
                                struct ast_frame tmp = { 0, };
+
                                tmp.frametype = AST_FRAME_VOICE;
                                ast_format_copy(&tmp.subclass.format, &framedata->last_format);
                                /* example: 8000hz / (1000 / 20ms) = 160 samples */
@@ -301,11 +310,13 @@ static struct ast_frame *hook_event_cb(struct ast_channel *chan, struct ast_fram
                                tmp.delivery = ast_tvadd(framedata->start_tv, ast_samp2tv(next, 1000));
                                tmp.offset = AST_FRIENDLY_OFFSET;
                                tmp.src  = "func_jitterbuffer interpolation";
+                               ast_frfree(frame);
                                frame = ast_frdup(&tmp);
                                break;
                        }
                        /* else fall through */
                case AST_JB_IMPL_NOFRAME:
+                       ast_frfree(frame);
                        frame = &ast_null_frame;
                        break;
                }
index 2153cb2d874d59359391b18ea02e669e30da49f6..2a606de61b1c29f8c9463633731892e633116c59 100644 (file)
@@ -647,7 +647,7 @@ static int jb_put_fixed(void *jb, struct ast_frame *fin, long now)
 static int jb_get_fixed(void *jb, struct ast_frame **fout, long now, long interpl)
 {
        struct fixed_jb *fixedjb = (struct fixed_jb *) jb;
-       struct fixed_jb_frame frame;
+       struct fixed_jb_frame frame = { .data = &ast_null_frame };
        int res;
 
        res = fixed_jb_get(fixedjb, &frame, now, interpl);
@@ -743,7 +743,7 @@ static int jb_put_adaptive(void *jb, struct ast_frame *fin, long now)
 static int jb_get_adaptive(void *jb, struct ast_frame **fout, long now, long interpl)
 {
        jitterbuf *adaptivejb = (jitterbuf *) jb;
-       jb_frame frame;
+       jb_frame frame = { .data = &ast_null_frame };
        int res;
 
        res = jb_get(adaptivejb, &frame, now, interpl);