aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2006-07-17 23:25:33 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2006-07-17 23:25:33 +0000
commit0770c281923e1e15fa06e8747597afd85fd3774f (patch)
treee5941586583c02d6e9c9dc3763bef4f2835e9d25
parent1b704ed045e47783e90273af8a90e498b017c97d (diff)
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: http://svn.digium.com/svn/asterisk/branches/1.2@37828 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r--frame.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/frame.c b/frame.c
index d2fc71cb1..2a7ee8610 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;
}