107 lines
2.7 KiB
Diff
107 lines
2.7 KiB
Diff
From 9fd716f6627c0bb3b63cef94780e20101d9616c3 Mon Sep 17 00:00:00 2001
|
|
From: liuchao173 <liuchao173@huawei.com>
|
|
Date: Thu, 7 Nov 2019 09:19:33 +0000
|
|
Subject: [PATCH 2/8] backport:
|
|
getline-clean-up-freeing-of-lines-from-getline.patch
|
|
|
|
It was noted that several calls to getline failed to free the resultant line,
|
|
which the man page for getline says to do even if the call fails. Clean that up
|
|
here
|
|
|
|
And while we're at it, merge some of the free calls so they're common to a
|
|
function where they can be, and not strewn all over the place
|
|
|
|
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
|
|
---
|
|
cputree.c | 29 +++++++++++++++++------------
|
|
1 file changed, 17 insertions(+), 12 deletions(-)
|
|
|
|
diff --git a/cputree.c b/cputree.c
|
|
index 5551784..91919ec 100644
|
|
--- a/cputree.c
|
|
+++ b/cputree.c
|
|
@@ -91,10 +91,10 @@ static void setup_banned_cpus(void)
|
|
if (getline(&line, &size, file) > 0) {
|
|
if (strlen(line) && line[0] != '\n')
|
|
cpulist_parse(line, strlen(line), isolated_cpus);
|
|
- free(line);
|
|
- line = NULL;
|
|
- size = 0;
|
|
}
|
|
+ free(line);
|
|
+ line = NULL;
|
|
+ size = 0;
|
|
fclose(file);
|
|
}
|
|
|
|
@@ -103,10 +103,10 @@ static void setup_banned_cpus(void)
|
|
if (getline(&line, &size, file) > 0) {
|
|
if (strlen(line) && line[0] != '\n')
|
|
cpulist_parse(line, strlen(line), nohz_full);
|
|
- free(line);
|
|
- line = NULL;
|
|
- size = 0;
|
|
}
|
|
+ free(line);
|
|
+ line = NULL;
|
|
+ size = 0;
|
|
fclose(file);
|
|
}
|
|
|
|
@@ -271,6 +271,7 @@ static void do_one_cpu(char *path)
|
|
int nodeid;
|
|
int packageid = 0;
|
|
unsigned int max_cache_index, cache_index, cache_stat;
|
|
+ int ret = 1;
|
|
|
|
/* skip offline cpus */
|
|
snprintf(new_path, ADJ_SIZE(path,"/online"), "%s/online", path);
|
|
@@ -278,14 +279,12 @@ static void do_one_cpu(char *path)
|
|
if (file) {
|
|
char *line = NULL;
|
|
size_t size = 0;
|
|
- if (getline(&line, &size, file)==0)
|
|
- return;
|
|
+ if (getline(&line, &size, file)>0)
|
|
+ ret = (line && line[0]=='0') ? 1 : 0;
|
|
fclose(file);
|
|
- if (line && line[0]=='0') {
|
|
- free(line);
|
|
- return;
|
|
- }
|
|
free(line);
|
|
+ if (ret)
|
|
+ return;
|
|
}
|
|
|
|
cpu = calloc(sizeof(struct topo_obj), 1);
|
|
@@ -327,6 +326,8 @@ static void do_one_cpu(char *path)
|
|
cpumask_parse_user(line, strlen(line), package_mask);
|
|
fclose(file);
|
|
free(line);
|
|
+ line = NULL;
|
|
+ size = 0;
|
|
}
|
|
/* try to read the package id */
|
|
snprintf(new_path, ADJ_SIZE(path, "/topology/physical_package_id"),
|
|
@@ -339,6 +340,8 @@ static void do_one_cpu(char *path)
|
|
packageid = strtoul(line, NULL, 10);
|
|
fclose(file);
|
|
free(line);
|
|
+ line = NULL;
|
|
+ size = 0;
|
|
}
|
|
|
|
/* try to read the cache mask; if it doesn't exist assume solitary */
|
|
@@ -372,6 +375,8 @@ static void do_one_cpu(char *path)
|
|
cpumask_parse_user(line, strlen(line), cache_mask);
|
|
fclose(file);
|
|
free(line);
|
|
+ line = NULL;
|
|
+ size = 0;
|
|
}
|
|
}
|
|
|
|
--
|
|
2.19.1
|