]> git.sesse.net Git - ffmpeg/commitdiff
hwcontext_vaapi: avoid fd leak in vaapi_device_derive
authorHaihao Xiang <haihao.xiang@intel.com>
Fri, 24 Jul 2020 07:29:03 +0000 (15:29 +0800)
committerMark Thompson <sw@jkqxz.net>
Mon, 27 Jul 2020 14:41:32 +0000 (15:41 +0100)
libavutil/hwcontext_vaapi.c

index b31cf95850262690e2a69000edc0382eb8874158..c1893f239db651a4494a43abb72c734c2f7aa3d0 100644 (file)
@@ -1678,8 +1678,13 @@ static int vaapi_device_derive(AVHWDeviceContext *ctx,
 #endif
 
         priv = av_mallocz(sizeof(*priv));
-        if (!priv)
+        if (!priv) {
+            if (fd != src_hwctx->fd) {
+                // The fd was opened in this function.
+                close(fd);
+            }
             return AVERROR(ENOMEM);
+        }
 
         if (fd == src_hwctx->fd) {
             // The fd is inherited from the source context and we are holding