v3dv: clean-up after obtaining an XCB connection
authorIago Toral Quiroga <itoral@igalia.com>
Thu, 17 Sep 2020 14:12:31 +0000 (16:12 +0200)
committerMarge Bot <eric+marge@anholt.net>
Tue, 13 Oct 2020 21:21:33 +0000 (21:21 +0000)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

src/broadcom/vulkan/v3dv_device.c

index b0980b4..5a3f305 100644 (file)
@@ -315,7 +315,12 @@ compute_heap_size()
 static int
 create_display_fd_xcb()
 {
+   int fd = -1;
+
    xcb_connection_t *conn = xcb_connect(NULL, NULL);
+   if (xcb_connection_has_error(conn))
+      goto finish;
+
    const xcb_setup_t *setup = xcb_get_setup(conn);
    xcb_screen_iterator_t iter = xcb_setup_roots_iterator(setup);
    xcb_screen_t *screen = iter.data;
@@ -325,17 +330,19 @@ create_display_fd_xcb()
    cookie = xcb_dri3_open(conn, screen->root, None);
    reply = xcb_dri3_open_reply(conn, cookie, NULL);
    if (!reply)
-      return -1;
+      goto finish;
 
-   if (reply->nfd != 1) {
-      free(reply);
-      return -1;
-   }
+   if (reply->nfd != 1)
+      goto finish;
 
-   int fd = xcb_dri3_open_reply_fds(conn, reply)[0];
-   free(reply);
+   fd = xcb_dri3_open_reply_fds(conn, reply)[0];
    fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
 
+finish:
+   xcb_disconnect(conn);
+   if (reply)
+      free(reply);
+
    return fd;
 }
 #endif