nvk: Fix segfault when opening DRI device file returns error
authorBenjamin Lee <benjamin@computer.surgery>
Fri, 9 Jun 2023 22:22:01 +0000 (15:22 -0700)
committerMarge Bot <emma+marge@anholt.net>
Fri, 4 Aug 2023 21:32:05 +0000 (21:32 +0000)
Previously, ver was unitialized on this path, causing UB on the
`if (ver)` branch after the out_err label.

Signed-off-by: Benjamin Lee <benjamin@computer.surgery>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24326>

src/nouveau/winsys/nouveau_device.c

index 2cc9ad5..dfade7e 100644 (file)
@@ -186,12 +186,13 @@ nouveau_ws_device_new(drmDevicePtr drm_device)
    const char *path = drm_device->nodes[DRM_NODE_RENDER];
    struct nouveau_ws_device *device = CALLOC_STRUCT(nouveau_ws_device);
    uint64_t value = 0;
+   drmVersionPtr ver = NULL;
 
    int fd = open(path, O_RDWR | O_CLOEXEC);
    if (fd < 0)
       goto out_err;
 
-   drmVersionPtr ver = drmGetVersion(fd);
+   ver = drmGetVersion(fd);
    if (!ver)
       goto out_err;