if asked to duplicate a frame that has no data, don't set the frame's data
authorRussell Bryant <russell@russellbryant.com>
Mon, 17 Jul 2006 23:31:24 +0000 (23:31 +0000)
committerRussell Bryant <russell@russellbryant.com>
Mon, 17 Jul 2006 23:31:24 +0000 (23:31 +0000)
pointer past the end of the buffer allocated for the new frame

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

frame.c

diff --git a/frame.c b/frame.c
index 4774f26..c2db41b 100644 (file)
--- a/frame.c
+++ b/frame.c
@@ -375,7 +375,7 @@ struct ast_frame *ast_frdup(struct ast_frame *f)
                srclen = strlen(f->src);
        if (srclen > 0)
                len += srclen + 1;
-       if (!(buf = ast_malloc(len)))
+       if (!(buf = ast_calloc(1, len)))
                return NULL;
        out = buf;
        /* Set us as having malloc'd header only, so it will eventually
@@ -387,16 +387,15 @@ struct ast_frame *ast_frdup(struct ast_frame *f)
        out->delivery = f->delivery;
        out->mallocd = AST_MALLOCD_HDR;
        out->offset = AST_FRIENDLY_OFFSET;
-       out->data = buf + sizeof(*out) + AST_FRIENDLY_OFFSET;
+       if (out->datalen) {
+               out->data = buf + sizeof(*out) + AST_FRIENDLY_OFFSET;
+               memcpy(out->data, f->data, out->datalen);       
+       }
        if (srclen > 0) {
                out->src = out->data + f->datalen;
                /* Must have space since we allocated for it */
                strcpy((char *)out->src, f->src);
-       } else
-               out->src = NULL;
-       out->prev = NULL;
-       out->next = NULL;
-       memcpy(out->data, f->data, out->datalen);       
+       }
        out->has_timing_info = f->has_timing_info;
        if (f->has_timing_info) {
                out->ts = f->ts;