From: Matt Roper Date: Wed, 30 Sep 2015 16:30:51 +0000 (-0700) Subject: xf86drm: Fix error handling for drmGetDevices() X-Git-Tag: libdrm-2.4.66~57 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8c4a1cbd98bd8d185d489395f33302a17db643a9;p=platform%2Fupstream%2Flibdrm.git xf86drm: Fix error handling for drmGetDevices() If the opendir() call in drmGetDevices() returns failure, we jump to an error label that calls closedir() and then returns. However this means that we're calling closedir(NULL) which may not be safe on all implementations. We are also leaking the local_devices array that was allocated before the opendir() call. Fix both of these issues by jumping to an earlier error label (to free local_devices) and guarding the closedir() call with a NULL test. Signed-off-by: Matt Roper [Emil Velikov: make the teardown symmetrical, remove the NULL check] Signed-off-by: Emil Velikov --- diff --git a/xf86drm.c b/xf86drm.c index c1cab1b..27313cc 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -3209,7 +3209,7 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices) sysdir = opendir(DRM_DIR_NAME); if (!sysdir) { ret = -errno; - goto close_sysdir; + goto free_locals; } i = 0; @@ -3274,15 +3274,15 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices) device_count++; } - free(local_devices); closedir(sysdir); + free(local_devices); return device_count; free_devices: drmFreeDevices(local_devices, i); - free(local_devices); - -close_sysdir: closedir(sysdir); + +free_locals: + free(local_devices); return ret; }