[FFmpeg-devel] [PATCH] hwcontext_vaapi: avoid fd leak in vaapi_device_derive

Mark Thompson sw at jkqxz.net
Mon Jul 27 17:47:37 EEST 2020


On 24/07/2020 08:29, Haihao Xiang wrote:
> ---
>   libavutil/hwcontext_vaapi.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
> index fb9be19647..a4dfaba92c 100644
> --- a/libavutil/hwcontext_vaapi.c
> +++ b/libavutil/hwcontext_vaapi.c
> @@ -1698,8 +1698,12 @@ static int vaapi_device_derive(AVHWDeviceContext *ctx,
>   #endif
>   
>           priv = av_mallocz(sizeof(*priv));
> -        if (!priv)
> +        if (!priv) {
> +            /* fd is opened in this function */
> +            if (fd != src_hwctx->fd)
> +                close(fd);
>               return AVERROR(ENOMEM);
> +        }
>   
>           if (fd == src_hwctx->fd) {
>               // The fd is inherited from the source context and we are holding

Yep.  Made the comment style consistent with the rest of the file and applied.

Thanks,

- Mark


More information about the ffmpeg-devel mailing list