Always free after getline().
Noticed by "NRK": https://www.openwall.com/lists/musl/2022/07/29/5
We don't have this problem elsewhere in bionic because it's so rare to
call getline() without a loop, and the free() is always outside the loop
because that's a handy optimization.
Test: treehugger
Change-Id: Iff8845aa226d87357b38cf4a285fc1be3cac5659
diff --git a/libc/bionic/sysinfo.cpp b/libc/bionic/sysinfo.cpp
index 897ef30..1e4a0e8 100644
--- a/libc/bionic/sysinfo.cpp
+++ b/libc/bionic/sysinfo.cpp
@@ -44,8 +44,8 @@
size_t allocated_size = 0;
if (getline(&line, &allocated_size, fp) != -1) {
cpu_count = GetCpuCountFromString(line);
- free(line);
}
+ free(line);
fclose(fp);
}
return cpu_count;