vl/winsys_dri: cleanup vl_screen_create error path
authorEmil Velikov <emil.l.velikov@gmail.com>
Mon, 10 Feb 2014 18:29:43 +0000 (18:29 +0000)
committerEmil Velikov <emil.l.velikov@gmail.com>
Sat, 22 Feb 2014 03:26:27 +0000 (03:26 +0000)
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Jakob Bornecrantz <jakob@vmware.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
src/gallium/auxiliary/vl/vl_winsys_dri.c

index fb4aaadd48acb5a0b614e4b11ef53f6f87e044ee..5d83e5799da0057ab25557e83aebeead8a14fbc4 100644 (file)
@@ -330,7 +330,7 @@ vl_screen_create(Display *display, int screen)
    dri2_query_cookie = xcb_dri2_query_version (scrn->conn, XCB_DRI2_MAJOR_VERSION, XCB_DRI2_MINOR_VERSION);
    dri2_query = xcb_dri2_query_version_reply (scrn->conn, dri2_query_cookie, &error);
    if (dri2_query == NULL || error != NULL || dri2_query->minor_version < 2)
-      goto free_screen;
+      goto free_query;
 
    s = xcb_setup_roots_iterator(xcb_get_setup(scrn->conn));
    while (screen--)
@@ -353,48 +353,54 @@ vl_screen_create(Display *display, int screen)
    connect_cookie = xcb_dri2_connect_unchecked(scrn->conn, s.data->root, driverType);
    connect = xcb_dri2_connect_reply(scrn->conn, connect_cookie, NULL);
    if (connect == NULL || connect->driver_name_length + connect->device_name_length == 0)
-      goto free_screen;
+      goto free_connect;
 
    device_name_length = xcb_dri2_connect_device_name_length(connect);
    device_name = CALLOC(1, device_name_length + 1);
+   if (!device_name)
+      goto free_connect;
    memcpy(device_name, xcb_dri2_connect_device_name(connect), device_name_length);
    fd = open(device_name, O_RDWR);
    free(device_name);
 
    if (fd < 0)
-      goto free_screen;
+      goto free_connect;
 
    if (drmGetMagic(fd, &magic))
-      goto free_screen;
+      goto free_connect;
 
    authenticate_cookie = xcb_dri2_authenticate_unchecked(scrn->conn, s.data->root, magic);
    authenticate = xcb_dri2_authenticate_reply(scrn->conn, authenticate_cookie, NULL);
 
    if (authenticate == NULL || !authenticate->authenticated)
-      goto free_screen;
+      goto free_authenticate;
 
    scrn->base.pscreen = driver_descriptor.create_screen(fd);
+
    if (!scrn->base.pscreen)
-      goto free_screen;
+      goto free_authenticate;
 
    scrn->base.pscreen->flush_frontbuffer = vl_dri2_flush_frontbuffer;
    vl_compositor_reset_dirty_area(&scrn->dirty_areas[0]);
    vl_compositor_reset_dirty_area(&scrn->dirty_areas[1]);
 
-   free(dri2_query);
-   free(connect);
    free(authenticate);
+   free(connect);
+   free(dri2_query);
+   free(error);
 
    return &scrn->base;
 
-free_screen:
-   FREE(scrn);
-
-   free(dri2_query);
-   free(connect);
+free_authenticate:
    free(authenticate);
+free_connect:
+   free(connect);
+free_query:
+   free(dri2_query);
    free(error);
 
+free_screen:
+   FREE(scrn);
    return NULL;
 }