Thread (2 messages) 2 messages, 2 authors, 9d ago

[PATCH iproute2] lib: fix memory leak in getcmdline()

flat view
COOLING9d

From: Mohammad abu saleh <hidden>
Date: 2026-10-01 02:31:36
Subsystem: library code, the rest · Maintainers: Andrew Morton, Linus Torvalds

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 <redacted>
---
 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help