intel: Handle malloc fails in context create
authorBen Widawsky <benjamin.widawsky@intel.com>
Fri, 27 Dec 2013 00:37:00 +0000 (16:37 -0800)
committerBen Widawsky <benjamin.widawsky@intel.com>
Fri, 10 Jan 2014 19:05:50 +0000 (11:05 -0800)
The previous code would just use the potentially unallocated variable,
which is probably okay most of the time, but not very nice to the user
of the library.

Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
intel/intel_bufmgr_gem.c

index 3b1f584..ad722dd 100644 (file)
@@ -3020,15 +3020,19 @@ drm_intel_gem_context_create(drm_intel_bufmgr *bufmgr)
        drm_intel_context *context = NULL;
        int ret;
 
+       context = calloc(1, sizeof(*context));
+       if (!context)
+               return NULL;
+
        VG_CLEAR(create);
        ret = drmIoctl(bufmgr_gem->fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE, &create);
        if (ret != 0) {
                DBG("DRM_IOCTL_I915_GEM_CONTEXT_CREATE failed: %s\n",
                    strerror(errno));
+               free(context);
                return NULL;
        }
 
-       context = calloc(1, sizeof(*context));
        context->ctx_id = create.ctx_id;
        context->bufmgr = bufmgr;