Kexec Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kexec-tools: Fix resource leaks in kexec.c
@ 2020-08-25  8:43 Youling Tang
  2020-09-02 16:27 ` Simon Horman
  0 siblings, 1 reply; 2+ messages in thread
From: Youling Tang @ 2020-08-25  8:43 UTC (permalink / raw)
  To: Simon Horman; +Cc: kexec

Add free() call when handling some error returns.

Signed-off-by: Youling Tang <tangyouling@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


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] kexec-tools: Fix resource leaks in kexec.c
  2020-08-25  8:43 [PATCH] kexec-tools: Fix resource leaks in kexec.c Youling Tang
@ 2020-09-02 16:27 ` Simon Horman
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Horman @ 2020-09-02 16:27 UTC (permalink / raw)
  To: Youling Tang; +Cc: kexec

On Tue, Aug 25, 2020 at 04:43:23PM +0800, Youling Tang wrote:
> Add free() call when handling some error returns.
> 
> Signed-off-by: Youling Tang <tangyouling@loongson.cn>

Is there a value in cleaning up like this immediately before exiting?

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-09-02 16:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-08-25  8:43 [PATCH] kexec-tools: Fix resource leaks in kexec.c Youling Tang
2020-09-02 16:27 ` Simon Horman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox