From: Michael Jeanson Date: Fri, 29 Jul 2022 15:12:57 +0000 (-0400) Subject: fix: add missing closedir in _get_max_cpuid_from_sysfs() X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=85f8af7b80f5d52ab099e7f73d3ac8f59c6bb1e9;p=lttng-ust.git fix: add missing closedir in _get_max_cpuid_from_sysfs() As reported by Coverity: *** CID 1490849: (RESOURCE_LEAK) /src/common/smp.c: 84 in _get_max_cpuid_from_sysfs() 78 * CPU num of 0. 79 */ 80 if (max_cpuid < 0 || max_cpuid > INT_MAX) 81 max_cpuid = -1; 82 83 end: >>> CID 1490849: (RESOURCE_LEAK) >>> Variable "cpudir" going out of scope leaks the storage it points to. 84 return max_cpuid; 85 } 86 87 /* 88 * As a fallback to parsing the CPU mask in "/sys/devices/system/cpu/possible", 89 * iterate on all the folders in "/sys/devices/system/cpu" that start with Change-Id: I2048e2473d66aaa2a275fe2923da84a7e105f235 Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- diff --git a/src/common/smp.c b/src/common/smp.c index 8c742028..88d66a40 100644 --- a/src/common/smp.c +++ b/src/common/smp.c @@ -73,6 +73,9 @@ int _get_max_cpuid_from_sysfs(const char *path) } } + if (closedir(cpudir)) + PERROR("closedir"); + /* * If the max CPU id is out of bound, set it to -1 so it results in a * CPU num of 0.