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 <basni@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Chad Versace <chadversary@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
diff --git a/dri.c b/dri.c
index 13d4833..12e6a30 100644
--- a/dri.c
+++ b/dri.c
@@ -196,8 +196,12 @@
 	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;