Netdev List
 help / color / mirror / Atom feed
* [PATCH iproute2] lib: fix memory leak in getcmdline()
@ 2026-10-01  2:31 Mohammad abu saleh
  2026-10-02 16:00 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Mohammad abu saleh @ 2026-10-01  2:31 UTC (permalink / raw)
  To: netdev; +Cc: stephen, Mohammad abu saleh

getline() may allocate line1 even when it returns -1, and the caller
must free the buffer on the error path.

When batch input ends with a missing continuation line, getcmdline()
returns without freeing line1. This can be reproduced with:

printf 'link show \\\n' | ./ip/ip -batch -

Free line1 before returning. Valgrind reports 120 bytes definitely
lost before this change.

Fixes: c2f3a0f94de9 ("Fix batch mode, allow continuation, comments, etc.")
Signed-off-by: Mohammad abu saleh <ml.abusaleh.ml@gmail.com>
---
 lib/utils.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/utils.c b/lib/utils.c
index 50602e59..6388d981 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -1372,6 +1372,7 @@ static ssize_t getcmdline(char **linep, size_t *lenp, FILE *in)
 		cc1 = getline(&line1, &len1, in);
 		if (cc1 < 0) {
 			fprintf(stderr, "Missing continuation line\n");
+			free(line1);
 			return cc1;
 		}
 
-- 
2.53.0


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

end of thread, other threads:[~2026-10-02 16:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-01  2:31 [PATCH iproute2] lib: fix memory leak in getcmdline() Mohammad abu saleh
2026-10-02 16:00 ` patchwork-bot+netdevbpf

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