OSDN Git Service

xf86drm: Fix error handling for drmGetDevice()
authorMatt Roper <matthew.d.roper@intel.com>
Fri, 16 Oct 2015 22:11:23 +0000 (15:11 -0700)
committerEmil Velikov <emil.l.velikov@gmail.com>
Tue, 20 Oct 2015 17:44:58 +0000 (18:44 +0100)
Some of the error conditions in drmGetDevice() can lead to us calling
closedir(NULL) or leaking memory.  Fix these conditions the same way we
did for drmGetDevices() in commit:

        commit 8c4a1cbd98bd8d185d489395f33302a17db643a9
        Author: Matt Roper <matthew.d.roper@intel.com>
        Date:   Wed Sep 30 09:30:51 2015 -0700

            xf86drm: Fix error handling for drmGetDevices()

Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
xf86drm.c

index a29db42..951edbb 100644 (file)
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -3108,7 +3108,7 @@ int drmGetDevice(int fd, drmDevicePtr *device)
     sysdir = opendir(DRM_DIR_NAME);
     if (!sysdir) {
         ret = -errno;
-        goto close_sysdir;
+        goto free_locals;
     }
 
     i = 0;
@@ -3165,16 +3165,16 @@ int drmGetDevice(int fd, drmDevicePtr *device)
     for (i = 1; i < node_count && local_devices[i]; i++)
             drmFreeDevice(&local_devices[i]);
 
-    free(local_devices);
     closedir(sysdir);
+    free(local_devices);
     return 0;
 
 free_devices:
     drmFreeDevices(local_devices, i);
-    free(local_devices);
-
-close_sysdir:
     closedir(sysdir);
+
+free_locals:
+    free(local_devices);
     return ret;
 }