[FFmpeg-devel] [PATCH v2 1/3] avutil/hwcontext_qsv: register free function for device_derive

Xiang, Haihao haihao.xiang at intel.com
Tue Jun 20 05:34:49 EEST 2023


On Ma, 2023-06-19 at 14:15 +0800, Tong Wu wrote:
> When qsv device is created by device_derive, the ctx->free function is
> not registered, causing potential memory leak because of not properly
> closing the MFX session.
> 
> Signed-off-by: Tong Wu <tong1.wu at intel.com>
> Signed-off-by: Wenbin Chen <wenbin.chen at intel.com>
> ---
>  libavutil/hwcontext_qsv.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
> index 4ed4242ddf..878ecd886e 100644
> --- a/libavutil/hwcontext_qsv.c
> +++ b/libavutil/hwcontext_qsv.c
> @@ -2094,6 +2094,15 @@ static int qsv_device_derive(AVHWDeviceContext *ctx,
>                               AVDictionary *opts, int flags)
>  {
>      mfxIMPL impl;
> +    QSVDevicePriv *priv;
> +
> +    priv = av_mallocz(sizeof(*priv));
> +    if (!priv)
> +        return AVERROR(ENOMEM);
> +
> +    ctx->user_opaque = priv;
> +    ctx->free = qsv_device_free;
> +    
>      impl = choose_implementation("hw_any", child_device_ctx->type);
>      return qsv_device_derive_from_child(ctx, impl,
>                                          child_device_ctx, flags);

Patchset LGTM and will apply

Thanks
Haihao




More information about the ffmpeg-devel mailing list