Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
vulkan-device-select: Don't leak drmDevicePtr
Browse files Browse the repository at this point in the history
ASAN found a leak:

```
Direct leak of 1440 byte(s) in 10 object(s) allocated from:
    #0 0x4a9a92 in calloc (build-Monado-CMake/src/xrt/targets/service/monado-service+0x4a9a92)
    android-rpi#1 0x7fdf82afed06 in drmDeviceAlloc build-drm/../drm/xf86drm.c:3933:14
    android-rpi#2 0x7fdf82b00203 in drmProcessPciDevice build-drm/../drm/xf86drm.c:3965:11
    android-rpi#3 0x7fdf82b00203 in process_device build-drm/../drm/xf86drm.c:4359:16
    #4 0x7fdf82b0485e in drmGetDevice2 build-drm/../drm/xf86drm.c:4528:15
    #5 0x7fdf70751113 in device_select_find_xcb_pci_default ../src/vulkan/device-select-layer/device_select_x11.c:95:13
    #6 0x7fdf70751113 in get_default_device ../src/vulkan/device-select-layer/device_select_layer.c:395:21
    #7 0x7fdf70751113 in device_select_EnumeratePhysicalDevices ../src/vulkan/device-select-layer/device_select_layer.c:456:33
```

Cc: mesa-stable
Reviewed-by: Bas Nieuwenhuizen <[email protected]>
Reviewed-by: Dave Airlie <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14068>
(cherry picked from commit 555f93c)
  • Loading branch information
Wallbraker authored and 1ace committed Dec 17, 2021
1 parent 26a01fc commit 4b38a27
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .pick_status.json
Original file line number Diff line number Diff line change
Expand Up @@ -3901,7 +3901,7 @@
"description": "vulkan-device-select: Don't leak drmDevicePtr",
"nominated": true,
"nomination_type": 0,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": null
},
Expand Down
5 changes: 4 additions & 1 deletion src/vulkan/device-select-layer/device_select_x11.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ int device_select_find_xcb_pci_default(struct device_pci_info *devices, uint32_t
int scrn;
xcb_connection_t *conn;
int default_idx = -1;
drmDevicePtr xdev = NULL;

conn = xcb_connect(NULL, &scrn);
if (!conn)
return -1;
Expand All @@ -91,7 +93,6 @@ int device_select_find_xcb_pci_default(struct device_pci_info *devices, uint32_t
if (dri3_fd == -1)
goto out;

drmDevicePtr xdev;
int ret = drmGetDevice2(dri3_fd, 0, &xdev);
close(dri3_fd);
if (ret < 0)
Expand All @@ -113,7 +114,9 @@ int device_select_find_xcb_pci_default(struct device_pci_info *devices, uint32_t
if (default_idx != -1)
break;
}

out:
drmFreeDevice(&xdev); /* Is NULL pointer safe. */
xcb_disconnect(conn);
return default_idx;
}

0 comments on commit 4b38a27

Please sign in to comment.