OSDN Git Service

Close fd if we aren't going to use it
authorKevin Strasser <kevin.strasser@intel.com>
Thu, 17 May 2018 20:45:03 +0000 (13:45 -0700)
committerKalyan Kondapally <kalyan.kondapally@intel.com>
Fri, 18 May 2018 01:50:21 +0000 (18:50 -0700)
File descriptors are left open and forgotten.
Make sure to clean up fds after use.

Jira: GSE-1595
Test: Build and boot on Android

Signed-off-by: Kevin Strasser <kevin.strasser@intel.com>
cros_gralloc/cros_gralloc_driver.cc

index 87b6475..f78c7e0 100644 (file)
@@ -13,6 +13,7 @@
 #include <cstdlib>
 #include <fcntl.h>
 #include <xf86drm.h>
+#include <unistd.h>
 
 cros_gralloc_driver::cros_gralloc_driver() : drv_(nullptr)
 {
@@ -59,11 +60,14 @@ int32_t cros_gralloc_driver::init()
                                continue;
 
                        version = drmGetVersion(fd);
-                       if (!version)
+                       if (!version) {
+                               close(fd);
                                continue;
+            }
 
                        if (undesired[i] && !strcmp(version->name, undesired[i])) {
                                drmFreeVersion(version);
+                               close(fd);
                                continue;
                        }