summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2010-01-06 15:39:49 +0000
committerChris Wilson <chris@chris-wilson.co.uk>2010-01-06 15:41:17 +0000
commit85fb3e55fdb7af9b5f59c1ec0f15d1950e601b05 (patch)
treeb43cb6cdf4247ac47d0f17e6b1d9dd9046938f6a
parentd1308f4fe7f94aae51ca9f70947aea8e09597f37 (diff)
modes: Free local resources after allocation failure in GETRESOURCES
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
-rw-r--r--xf86drmMode.c38
1 files changed, 29 insertions, 9 deletions
diff --git a/xf86drmMode.c b/xf86drmMode.c
index 7edc625a..44ef05bc 100644
--- a/xf86drmMode.c
+++ b/xf86drmMode.c
@@ -146,14 +146,26 @@ retry:
counts = res;
- if (res.count_fbs)
+ if (res.count_fbs) {
res.fb_id_ptr = VOID2U64(drmMalloc(res.count_fbs*sizeof(uint32_t)));
- if (res.count_crtcs)
+ if (!res.fb_id_ptr)
+ goto err_allocs;
+ }
+ if (res.count_crtcs) {
res.crtc_id_ptr = VOID2U64(drmMalloc(res.count_crtcs*sizeof(uint32_t)));
- if (res.count_connectors)
+ if (!res.crtc_id_ptr)
+ goto err_allocs;
+ }
+ if (res.count_connectors) {
res.connector_id_ptr = VOID2U64(drmMalloc(res.count_connectors*sizeof(uint32_t)));
- if (res.count_encoders)
+ if (!res.connector_id_ptr)
+ goto err_allocs;
+ }
+ if (res.count_encoders) {
res.encoder_id_ptr = VOID2U64(drmMalloc(res.count_encoders*sizeof(uint32_t)));
+ if (!res.encoder_id_ptr)
+ goto err_allocs;
+ }
if (drmIoctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &res))
goto err_allocs;
@@ -189,11 +201,19 @@ retry:
r->count_crtcs = res.count_crtcs;
r->count_connectors = res.count_connectors;
r->count_encoders = res.count_encoders;
- /* TODO we realy should test if these allocs fails. */
- r->fbs = drmAllocCpy(U642VOID(res.fb_id_ptr), res.count_fbs, sizeof(uint32_t));
- r->crtcs = drmAllocCpy(U642VOID(res.crtc_id_ptr), res.count_crtcs, sizeof(uint32_t));
- r->connectors = drmAllocCpy(U642VOID(res.connector_id_ptr), res.count_connectors, sizeof(uint32_t));
- r->encoders = drmAllocCpy(U642VOID(res.encoder_id_ptr), res.count_encoders, sizeof(uint32_t));
+
+ r->fbs = drmAllocCpy(U642VOID(res.fb_id_ptr), res.count_fbs, sizeof(uint32_t));
+ r->crtcs = drmAllocCpy(U642VOID(res.crtc_id_ptr), res.count_crtcs, sizeof(uint32_t));
+ r->connectors = drmAllocCpy(U642VOID(res.connector_id_ptr), res.count_connectors, sizeof(uint32_t));
+ r->encoders = drmAllocCpy(U642VOID(res.encoder_id_ptr), res.count_encoders, sizeof(uint32_t));
+ if (!r->fbs || !r->crtcs || !r->connectors || !r->encoders) {
+ drmFree(r->fbs);
+ drmFree(r->crtcs);
+ drmFree(r->connectors);
+ drmFree(r->encoders);
+ drmFree(r);
+ r = 0;
+ }
err_allocs:
drmFree(U642VOID(res.fb_id_ptr));