xf86drm: fix mem leak in drm_usb_dev_path()

`sysfs_uevent_get()` returns a `strndup()`ed string, which must be `free()`d.

Fixes: bf63f8acdc ("libdrm: Handle usb_interface devices for usb parsing")
Reviewed-by: Simon Ser <contact@emersion.fr>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
main
Eric Engestrom 2021-08-13 21:19:13 +01:00
parent 1d29e1df8b
commit 1a4c0ec9ae
1 changed files with 7 additions and 2 deletions

View File

@ -3998,6 +3998,7 @@ free_device:
static int drm_usb_dev_path(int maj, int min, char *path, size_t len)
{
char *value, *tmp_path, *slash;
bool usb_device, usb_interface;
snprintf(path, len, "/sys/dev/char/%d:%d/device", maj, min);
@ -4005,9 +4006,13 @@ static int drm_usb_dev_path(int maj, int min, char *path, size_t len)
if (!value)
return -ENOENT;
if (strcmp(value, "usb_device") == 0)
usb_device = strcmp(value, "usb_device") == 0;
usb_interface = strcmp(value, "usb_interface") == 0;
free(value);
if (usb_device)
return 0;
if (strcmp(value, "usb_interface") != 0)
if (!usb_interface)
return -ENOTSUP;
/* The parent of a usb_interface is a usb_device */