ff_vaapi_encode_close() is not enough to free the resources like cbs if initialization failure happens after codec->configure (except for vp8/vp9). We need to call avctx->codec->close() to deallocate, otherwise memory leak happens. Add FF_CODEC_CAP_INIT_CLEANUP for vaapi encoders and deallocate the resources at free_and_end inside avcodec_open2().
Showing the changes to libavcodec/vaapi_encode_mpeg2.c (1 of 7 files). Show all
Unified · Split
| @@ -702,6 +702,7 @@ AVCodec ff_mpeg2_vaapi_encoder = { · 701 unmodified lines | ||
| 702 | 702 | .close = &vaapi_encode_mpeg2_close, |
| 703 | 703 | .priv_class = &vaapi_encode_mpeg2_class, |
| 704 | 704 | .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE, |
| 705 | + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, | |
| 705 | 706 | .defaults = vaapi_encode_mpeg2_defaults, |
| 706 | 707 | .pix_fmts = (const enum AVPixelFormat[]) { |
| 707 | 708 | AV_PIX_FMT_VAAPI, |