diff mbox

[libdrm,v2,2/2] drm: fix multi GPU drmFreeDevices memory leak

Message ID 1468487456-28666-2-git-send-email-Qiang.Yu@amd.com (mailing list archive)
State New, archived
Headers show

Commit Message

Qiang Yu July 14, 2016, 9:10 a.m. UTC
When in multi GPU case, devices array may have some
NULL "hole" in between two devices. So check all
array elements and free non-NULL device.

Change-Id: Ifc32d240f895059bc4b19138cb81de38d99fb88a
Signed-off-by: Qiang Yu <Qiang.Yu@amd.com>
---
 xf86drm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/xf86drm.c b/xf86drm.c
index 19001db..32bedeb 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -2992,8 +2992,9 @@  void drmFreeDevices(drmDevicePtr devices[], int count)
     if (devices == NULL)
         return;
 
-    for (i = 0; i < count && devices[i] != NULL; i++)
-        drmFreeDevice(&devices[i]);
+    for (i = 0; i < count; i++)
+        if (devices[i])
+            drmFreeDevice(&devices[i]);
 }
 
 static int drmProcessPciDevice(drmDevicePtr *device, const char *d_name,