From da6910c35b2e72ce9cf6b06f4b1ceb1d62e5c975 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Mon, 17 Jul 2006 23:31:24 +0000 Subject: if asked to duplicate a frame that has no data, don't set the frame's data 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 | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'frame.c') diff --git a/frame.c b/frame.c index 4774f2672..c2db41bad 100644 --- 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; -- cgit v1.2.3