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>
main
Seung-Woo Kim 2017-03-27 11:09:29 +09:00 committed by Emil Velikov
parent 2dc30dd527
commit 7b806e8789
1 changed files with 12 additions and 6 deletions

View File

@ -994,8 +994,10 @@ char *drmGetBusid(int fd)
if (drmIoctl(fd, DRM_IOCTL_GET_UNIQUE, &u))
return NULL;
u.unique = drmMalloc(u.unique_len + 1);
if (drmIoctl(fd, DRM_IOCTL_GET_UNIQUE, &u))
if (drmIoctl(fd, DRM_IOCTL_GET_UNIQUE, &u)) {
drmFree(u.unique);
return NULL;
}
u.unique[u.unique_len] = '\0';
return u.unique;
@ -1523,14 +1525,12 @@ drm_context_t *drmGetReservedContextList(int fd, int *count)
if (!(list = drmMalloc(res.count * sizeof(*list))))
return NULL;
if (!(retval = drmMalloc(res.count * sizeof(*retval)))) {
drmFree(list);
return NULL;
}
if (!(retval = drmMalloc(res.count * sizeof(*retval))))
goto err_free_list;
res.contexts = list;
if (drmIoctl(fd, DRM_IOCTL_RES_CTX, &res))
return NULL;
goto err_free_context;
for (i = 0; i < res.count; i++)
retval[i] = list[i].handle;
@ -1538,6 +1538,12 @@ drm_context_t *drmGetReservedContextList(int fd, int *count)
*count = res.count;
return retval;
err_free_list:
drmFree(list);
err_free_context:
drmFree(retval);
return NULL;
}
void drmFreeReservedContextList(drm_context_t *pt)