Needed to free allocated memory when one of the allocations fails.
---
libavcodec/ac3enc.c | 59 ++++++++++++++++++++++++++-------------------------
1 files changed, 30 insertions(+), 29 deletions(-)
diff --git libavcodec/ac3enc.c libavcodec/ac3enc.c
index 43b341d..23e2edf 100644
--- libavcodec/ac3enc.c
+++ libavcodec/ac3enc.c
@@ -961,6 +961,35 @@ static unsigned int pow_poly(unsigned int a, unsigned int n, unsigned int poly)
return r;
}
+static av_cold int AC3_encode_close(AVCodecContext *avctx)
+{
+ AC3EncodeContext *s = avctx->priv_data;
+ int blk, ch;
+
+ av_freep(&s->windowed_samples);
+ av_freep(&s->bap_buffer);
+ av_freep(&s->bap1_buffer);
+ av_freep(&s->mdct_coef_buffer);
+ av_freep(&s->exp_buffer);
+ av_freep(&s->psd_buffer);
+ av_freep(&s->mask_buffer);
+ for (ch = 0; ch < s->channels; ch++) {
+ av_freep(&s->planar_samples[ch]);
+ }
+ for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+ av_freep(&s->blocks[blk].bap);
+ av_freep(&s->blocks[blk].mdct_coef);
+ av_freep(&s->blocks[blk].exp);
+ av_freep(&s->blocks[blk].psd);
+ av_freep(&s->blocks[blk].mask);
+ }
+
+ mdct_end(&s->mdct);
+
+ av_freep(&avctx->coded_frame);
+ return 0;
+}
+
static av_cold int AC3_encode_init(AVCodecContext *avctx)
{
int freq = avctx->sample_rate;
@@ -1119,6 +1148,7 @@ static av_cold int AC3_encode_init(AVCodecContext *avctx)
return 0;
alloc_fail:
+ AC3_encode_close(avctx);
return AVERROR(ENOMEM);
}
@@ -1589,35 +1619,6 @@ static int AC3_encode_frame(AVCodecContext *avctx,
return s->frame_size;
}
-static av_cold int AC3_encode_close(AVCodecContext *avctx)
-{
- AC3EncodeContext *s = avctx->priv_data;
- int blk, ch;
-
- av_freep(&s->windowed_samples);
- av_freep(&s->bap_buffer);
- av_freep(&s->bap1_buffer);
- av_freep(&s->mdct_coef_buffer);
- av_freep(&s->exp_buffer);
- av_freep(&s->psd_buffer);
- av_freep(&s->mask_buffer);
- for (ch = 0; ch < s->channels; ch++) {
- av_freep(&s->planar_samples[ch]);
- }
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
- av_freep(&s->blocks[blk].bap);
- av_freep(&s->blocks[blk].mdct_coef);
- av_freep(&s->blocks[blk].exp);
- av_freep(&s->blocks[blk].psd);
- av_freep(&s->blocks[blk].mask);
- }
-
- mdct_end(&s->mdct);
-
- av_freep(&avctx->coded_frame);
- return 0;
-}
-
#ifdef TEST
/*************************************************************************/
/* TEST */
_______________________________________________
FFmpeg-soc mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc