[PATCH] kexec-tools: Fix resource leaks in kexec.c

Youling Tang tangyouling at loongson.cn
Tue Aug 25 04:43:23 EDT 2020


Add free() call when handling some error returns.

Signed-off-by: Youling Tang <tangyouling at loongson.cn>
---
 kexec/kexec.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/kexec/kexec.c b/kexec/kexec.c
index a62b362..a0f0908 100644
--- a/kexec/kexec.c
+++ b/kexec/kexec.c
@@ -1128,11 +1128,15 @@ char *get_command_line(void)
 		die("Could not allocate memory to read /proc/cmdline.");
 
 	fp = fopen("/proc/cmdline", "r");
-	if (!fp)
+	if (!fp) {
+		free(line);
 		die("Could not open /proc/cmdline.");
+	}
 
-	if (fgets(line, sizeof_line, fp) == NULL)
+	if (fgets(line, sizeof_line, fp) == NULL) {
+		free(line);
 		die("Can't read /proc/cmdline.");
+	}
 
 	fclose(fp);
 
-- 
2.1.0




More information about the kexec mailing list