lib: fix memory leak in getcmdline()
Subsystems (3)
PATCH 1/1 lib: fix memory leak in getcmdline()
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.
--- lib/utils.c | 1 + 1 file changed, 1 insertion(+)
lib/utils.c +1 -0
@@ -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; }
Signature · 1 line
2.53.0
This patch was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:
Hello:
This patch was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:
Quoted 9 lines · On Thu, 1 Oct 2026 04:31:29 +0200 you wrote:
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 -
[...]
Here is the summary with links:
- [iproute2] lib: fix memory leak in getcmdline()
https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=fde561a2a135
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html