aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-10-19 20:23:54 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2021-02-27 07:20:58 +0100
commit4e5a97e3932b519e9003b206ecd0bbfde3e61411 (patch)
treee988038c270e041901d9462172a0b8e1f36801b5
parent78ac14f280f9bf71c824ef11c40f0a0f3c877b4c (diff)
downloadffmpeg-4e5a97e3932b519e9003b206ecd0bbfde3e61411.tar.gz
avcodec/vp3: Fix memleak upon init failure
Up until now, there was no cleanup in case initializing the Theora VLC tables failed, leading to memleaks. This commit gets rid of them by setting the FF_CODEC_CAP_INIT_CLEANUP flag for all decoders in vp3.c; this also allows to remove some (now redundant) cleanup code. Reviewed-by: Peter Ross <pross@xvid.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> (cherry picked from commit a01ca21bbbd41ad86ca58f2c7575c92a36a4b722)
-rw-r--r--libavcodec/vp3.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
index c79b57e124..c411971816 100644
--- a/libavcodec/vp3.c
+++ b/libavcodec/vp3.c
@@ -2287,7 +2287,6 @@ static av_cold int allocate_tables(AVCodecContext *avctx)
!s->superblock_fragments || !s->macroblock_coding ||
!s->dc_pred_row ||
!s->motion_val[0] || !s->motion_val[1]) {
- vp3_decode_end(avctx);
return -1;
}
@@ -2302,12 +2301,8 @@ static av_cold int init_frames(Vp3DecodeContext *s)
s->last_frame.f = av_frame_alloc();
s->golden_frame.f = av_frame_alloc();
- if (!s->current_frame.f || !s->last_frame.f || !s->golden_frame.f) {
- av_frame_free(&s->current_frame.f);
- av_frame_free(&s->last_frame.f);
- av_frame_free(&s->golden_frame.f);
+ if (!s->current_frame.f || !s->last_frame.f || !s->golden_frame.f)
return AVERROR(ENOMEM);
- }
return 0;
}
@@ -3224,7 +3219,8 @@ AVCodec ff_theora_decoder = {
AV_CODEC_CAP_FRAME_THREADS,
.flush = vp3_decode_flush,
.update_thread_context = ONLY_IF_THREADS_ENABLED(vp3_update_thread_context),
- .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING | FF_CODEC_CAP_ALLOCATE_PROGRESS,
+ .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING | FF_CODEC_CAP_ALLOCATE_PROGRESS |
+ FF_CODEC_CAP_INIT_CLEANUP,
};
#endif
@@ -3241,7 +3237,7 @@ AVCodec ff_vp3_decoder = {
AV_CODEC_CAP_FRAME_THREADS,
.flush = vp3_decode_flush,
.update_thread_context = ONLY_IF_THREADS_ENABLED(vp3_update_thread_context),
- .caps_internal = FF_CODEC_CAP_ALLOCATE_PROGRESS,
+ .caps_internal = FF_CODEC_CAP_ALLOCATE_PROGRESS | FF_CODEC_CAP_INIT_CLEANUP,
};
#if CONFIG_VP4_DECODER
@@ -3258,6 +3254,6 @@ AVCodec ff_vp4_decoder = {
AV_CODEC_CAP_FRAME_THREADS,
.flush = vp3_decode_flush,
.update_thread_context = ONLY_IF_THREADS_ENABLED(vp3_update_thread_context),
- .caps_internal = FF_CODEC_CAP_ALLOCATE_PROGRESS,
+ .caps_internal = FF_CODEC_CAP_ALLOCATE_PROGRESS | FF_CODEC_CAP_INIT_CLEANUP,
};
#endif