aboutsummaryrefslogtreecommitdiffstats
path: root/codecs
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2008-01-15 23:26:52 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2008-01-15 23:26:52 +0000
commita44f64d6e6c71d54418759c2750a7dbc64f9a0c6 (patch)
tree698e81f4d354cd447cb6b6f592f3b2ae0aa46789 /codecs
parenta3687fd864f0e4ac309186a25da7cb4472451a96 (diff)
Commit a fix for some memory access errors pointed out by the valgrind2.txt
output on issue #11698. The issue here is that it is possible for an instance of a translator to get destroyed while the frame allocated as a part of the translator is still being processed. Specifically, this is possible anywhere between a call to ast_read() and ast_frame_free(), which is _a lot_ of places in the code. The reason this happens is that the channel might get masqueraded during this time. During a masquerade, existing translation paths get destroyed. So, this patch fixes the issue in an API and ABI compatible way. (This one is for you, paravoid!) It changes an int in ast_frame to be used as flag bits. The 1 bit is still used to indicate that the frame contains timing information. Also, a second flag has been added to indicate that the frame came from a translator. When a frame with this flag gets released and has this flag, a function is called in translate.c to let it know that this frame is doing being processed. At this point, the flag gets cleared. Also, if the translator was requested to be destroyed while its internal frame still had this flag set, its destruction has been deffered until it finds out that the frame is no longer being processed. Admittedly, this feels like a hack. But, it does fix the issue, and I was not able to think of a better solution ... git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@98943 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'codecs')
-rw-r--r--codecs/codec_zap.c35
1 files changed, 18 insertions, 17 deletions
diff --git a/codecs/codec_zap.c b/codecs/codec_zap.c
index f04f11021..f4ea5886f 100644
--- a/codecs/codec_zap.c
+++ b/codecs/codec_zap.c
@@ -114,7 +114,6 @@ struct pvt {
int lasttotalms;
#endif
struct zt_transcode_header *hdr;
- struct ast_frame f;
};
static int transcoder_show(int fd, int argc, char **argv)
@@ -186,13 +185,14 @@ static struct ast_frame *zap_frameout(struct ast_trans_pvt *pvt)
if (ztp->fake == 2) {
ztp->fake = 1;
- ztp->f.frametype = AST_FRAME_VOICE;
- ztp->f.subclass = 0;
- ztp->f.samples = 160;
- ztp->f.data = NULL;
- ztp->f.offset = 0;
- ztp->f.datalen = 0;
- ztp->f.mallocd = 0;
+ pvt->f.frametype = AST_FRAME_VOICE;
+ pvt->f.subclass = 0;
+ pvt->f.samples = 160;
+ pvt->f.data = NULL;
+ pvt->f.offset = 0;
+ pvt->f.datalen = 0;
+ pvt->f.mallocd = 0;
+ ast_set_flag(&pvt->f, AST_FRFLAG_FROM_TRANSLATOR);
pvt->samples = 0;
} else if (ztp->fake == 1) {
return NULL;
@@ -205,14 +205,15 @@ static struct ast_frame *zap_frameout(struct ast_trans_pvt *pvt)
ztp->lasttotalms = ztp->totalms;
}
#endif
- ztp->f.frametype = AST_FRAME_VOICE;
- ztp->f.subclass = hdr->dstfmt;
- ztp->f.samples = hdr->dstsamples;
- ztp->f.data = hdr->dstdata + hdr->dstoffset;
- ztp->f.offset = hdr->dstoffset;
- ztp->f.datalen = hdr->dstlen;
- ztp->f.mallocd = 0;
- pvt->samples -= ztp->f.samples;
+ pvt->f.frametype = AST_FRAME_VOICE;
+ pvt->f.subclass = hdr->dstfmt;
+ pvt->f.samples = hdr->dstsamples;
+ pvt->f.data = hdr->dstdata + hdr->dstoffset;
+ pvt->f.offset = hdr->dstoffset;
+ pvt->f.datalen = hdr->dstlen;
+ pvt->f.mallocd = 0;
+ ast_set_flag(&pvt->f, AST_FRFLAG_FROM_TRANSLATOR);
+ pvt->samples -= pvt->f.samples;
hdr->dstlen = 0;
} else {
@@ -226,7 +227,7 @@ static struct ast_frame *zap_frameout(struct ast_trans_pvt *pvt)
}
}
- return &ztp->f;
+ return &pvt->f;
}
static void zap_destroy(struct ast_trans_pvt *pvt)