aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeung-Woo Kim2017-03-26 21:09:29 -0500
committerEmil Velikov2017-04-03 11:46:06 -0500
commit7b806e87890182ac1b6181a848e03cd5c7db97ec (patch)
tree20f88297cd4b05f9ab8bf06980ac398e6c1c7de9 /xf86drm.c
parent2dc30dd5279fea1838f181724fb699a3689f582b (diff)
downloadexternal-libgbm-7b806e87890182ac1b6181a848e03cd5c7db97ec.tar.gz
external-libgbm-7b806e87890182ac1b6181a848e03cd5c7db97ec.tar.xz
external-libgbm-7b806e87890182ac1b6181a848e03cd5c7db97ec.zip
xf86drm: remove memory leaks in drmGetBusid/drmGetReservedContextList
In error path of drmGetBusid() and drmGetReservedContextList(), there are memory leaks for error path. So this removes them. Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com> Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com> Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Diffstat (limited to 'xf86drm.c')
-rw-r--r--xf86drm.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/xf86drm.c b/xf86drm.c
index 88f86ed5..685cf69d 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -994,8 +994,10 @@ char *drmGetBusid(int fd)
994 if (drmIoctl(fd, DRM_IOCTL_GET_UNIQUE, &u)) 994 if (drmIoctl(fd, DRM_IOCTL_GET_UNIQUE, &u))
995 return NULL; 995 return NULL;
996 u.unique = drmMalloc(u.unique_len + 1); 996 u.unique = drmMalloc(u.unique_len + 1);
997 if (drmIoctl(fd, DRM_IOCTL_GET_UNIQUE, &u)) 997 if (drmIoctl(fd, DRM_IOCTL_GET_UNIQUE, &u)) {
998 drmFree(u.unique);
998 return NULL; 999 return NULL;
1000 }
999 u.unique[u.unique_len] = '\0'; 1001 u.unique[u.unique_len] = '\0';
1000 1002
1001 return u.unique; 1003 return u.unique;
@@ -1523,14 +1525,12 @@ drm_context_t *drmGetReservedContextList(int fd, int *count)
1523 1525
1524 if (!(list = drmMalloc(res.count * sizeof(*list)))) 1526 if (!(list = drmMalloc(res.count * sizeof(*list))))
1525 return NULL; 1527 return NULL;
1526 if (!(retval = drmMalloc(res.count * sizeof(*retval)))) { 1528 if (!(retval = drmMalloc(res.count * sizeof(*retval))))
1527 drmFree(list); 1529 goto err_free_list;
1528 return NULL;
1529 }
1530 1530
1531 res.contexts = list; 1531 res.contexts = list;
1532 if (drmIoctl(fd, DRM_IOCTL_RES_CTX, &res)) 1532 if (drmIoctl(fd, DRM_IOCTL_RES_CTX, &res))
1533 return NULL; 1533 goto err_free_context;
1534 1534
1535 for (i = 0; i < res.count; i++) 1535 for (i = 0; i < res.count; i++)
1536 retval[i] = list[i].handle; 1536 retval[i] = list[i].handle;
@@ -1538,6 +1538,12 @@ drm_context_t *drmGetReservedContextList(int fd, int *count)
1538 1538
1539 *count = res.count; 1539 *count = res.count;
1540 return retval; 1540 return retval;
1541
1542err_free_list:
1543 drmFree(list);
1544err_free_context:
1545 drmFree(retval);
1546 return NULL;
1541} 1547}
1542 1548
1543void drmFreeReservedContextList(drm_context_t *pt) 1549void drmFreeReservedContextList(drm_context_t *pt)