diff --git a/libavcodec/h264_refs.c b/libavcodec/h264_refs.c index 619f2edf84..9d0641a0db 100644 --- a/libavcodec/h264_refs.c +++ b/libavcodec/h264_refs.c @@ -515,7 +515,8 @@ void ff_h264_remove_all_refs(H264Context *h) if (h->short_ref_count && !h->last_pic_for_ec.f->data[0]) { ff_h264_unref_picture(h, &h->last_pic_for_ec); - ff_h264_ref_picture(h, &h->last_pic_for_ec, h->short_ref[0]); + if (h->short_ref[0]->f->buf[0]) + ff_h264_ref_picture(h, &h->last_pic_for_ec, h->short_ref[0]); } for (i = 0; i < h->short_ref_count; i++) { diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c index cc1e592ac9..2f4d531601 100644 --- a/libavcodec/videotoolbox.c +++ b/libavcodec/videotoolbox.c @@ -353,6 +353,8 @@ static int videotoolbox_common_end_frame(AVCodecContext *avctx, AVFrame *frame) AVVideotoolboxContext *videotoolbox = avctx->hwaccel_context; VTContext *vtctx = avctx->internal->hwaccel_priv_data; + av_buffer_unref(&frame->buf[0]); + if (!videotoolbox->session || !vtctx->bitstream) return AVERROR_INVALIDDATA;