From 09a334573ec5bc506af5ab58d847b9b813a7a920 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Mon, 17 Jul 2006 23:25:33 +0000 Subject: [PATCH] if asked to duplicate a frame that has no data, don't set the frame's data pointer past the end of the allocatted buffer for the new frame git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.2@37828 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- frame.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/frame.c b/frame.c index d2fc71cb18..2a7ee86105 100644 --- a/frame.c +++ b/frame.c @@ -374,7 +374,7 @@ struct ast_frame *ast_frdup(struct ast_frame *f) srclen = strlen(f->src); if (srclen > 0) len += srclen + 1; - buf = malloc(len); + buf = calloc(1, len); if (!buf) return NULL; out = buf; @@ -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(struct ast_frame) + AST_FRIENDLY_OFFSET; + if (out->datalen) { + out->data = buf + sizeof(struct ast_frame) + 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); + } return out; } -- 2.47.2