From 03af6f6b13ba78ff583cfb3cd8d9cf43f2a10e35 Mon Sep 17 00:00:00 2001 From: Bas Nieuwenhuizen Date: Mon, 12 Jul 2021 13:25:31 +0200 Subject: [PATCH] dri: Fix memory leak. The string gets allocated in libdrm with strdup so it is the callers responsibility to free. While at it, also add a proper NULL check, as NULL can be returned (e.g. when the file doesn't exist in a container). Found by inspection. BUG=none TEST=compile and confirm the UI still starts on Zork. Change-Id: Ib8701f7a15f030458885eade0effe5c8fe09dc83 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3017875 Tested-by: Bas Nieuwenhuizen Tested-by: Gurchetan Singh Reviewed-by: Chad Versace Reviewed-by: Gurchetan Singh Commit-Queue: Gurchetan Singh --- dri.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dri.c b/dri.c index 13d4833..12e6a30 100644 --- a/dri.c +++ b/dri.c @@ -196,8 +196,12 @@ int dri_init(struct driver *drv, const char *dri_so_path, const char *driver_suf const __DRIextension *loader_extensions[] = { NULL }; struct dri_driver *dri = drv->priv; + char *node_name = drmGetRenderDeviceNameFromFd(drv_get_fd(drv)); + if (!node_name) + return -ENODEV; - dri->fd = open(drmGetRenderDeviceNameFromFd(drv_get_fd(drv)), O_RDWR); + dri->fd = open(node_name, O_RDWR); + free(node_name); if (dri->fd < 0) return -ENODEV;