diff mbox series

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

Message ID 20200724072903.1172232-1-haihao.xiang@intel.com
State Accepted
Headers show
Series [FFmpeg-devel] hwcontext_vaapi: avoid fd leak in vaapi_device_derive | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Xiang, Haihao July 24, 2020, 7:29 a.m. UTC
---
 libavutil/hwcontext_vaapi.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Mark Thompson July 27, 2020, 2:47 p.m. UTC | #1
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
diff mbox series

Patch

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