From: Martin Mares Date: Thu, 12 Jul 2018 11:59:52 +0000 (+0200) Subject: Sysfs: fixed sysfs_deref_link() X-Git-Tag: v3.6.1~1 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=f15db375b857d3a2663dd7e13da0500c4daec762;p=pciutils.git Sysfs: fixed sysfs_deref_link() The function canonicalize_file_name() is GLIBC-specific, use realpath() instead, which is available also on MUSL libc. Also, it leaked memory. --- diff --git a/lib/sysfs.c b/lib/sysfs.c index 1adb50f..42c88c6 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -133,7 +133,8 @@ sysfs_deref_link(struct pci_dev *d, char *link_name) sysfs_obj_name(d, "", path); strcat(path, rel_path); - return canonicalize_file_name(path); + // Returns a pointer to malloc'ed memory + return realpath(path, NULL); } static int @@ -329,7 +330,14 @@ sysfs_fill_info(struct pci_dev *d, int flags) d->numa_node = sysfs_get_value(d, "numa_node", 0); if ((flags & PCI_FILL_DT_NODE) && !(d->known_fields & PCI_FILL_DT_NODE)) - pci_set_property(d, PCI_FILL_DT_NODE, sysfs_deref_link(d, "of_node")); + { + char *node = sysfs_deref_link(d, "of_node"); + if (node) + { + pci_set_property(d, PCI_FILL_DT_NODE, node); + free(node); + } + } return pci_generic_fill_info(d, flags); }