diff --git a/libavcodec/mdec.c b/libavcodec/mdec.c
index fa9661e19f96f7e0eb17e0e8d82158152cbb4701..9ae22585831e930b957864f757957ab5b2440b61 100644
--- a/libavcodec/mdec.c
+++ b/libavcodec/mdec.c
@@ -239,6 +239,8 @@ static av_cold int decode_init(AVCodecContext *avctx){
 static av_cold int decode_end(AVCodecContext *avctx){
     MDECContext * const a = avctx->priv_data;
 
+    if(a->picture.data[0])
+        avctx->release_buffer(avctx, &a->picture);
     av_freep(&a->bitstream_buffer);
     av_freep(&a->picture.qscale_table);
     a->bitstream_buffer_size=0;