107 lines
2.7 KiB
Diff
107 lines
2.7 KiB
Diff
From 50f7f4641534c8137b329f2c6cdeaa20987c9382 Mon Sep 17 00:00:00 2001
|
|
From: Neil Horman <nhorman@hmswarspite.think-freely.org>
|
|
Date: Mon, 30 Sep 2019 11:46:37 -0400
|
|
Subject: [PATCH 19/53] getline: clean up freeing of lines from getline
|
|
|
|
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 91c6111..a90cbbe 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.23.0
|
|
|