* [PATCH iproute] lib: fix leak on realloc() failure
@ 2026-10-01 18:37 Stephen Hemminger
2026-10-02 16:00 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Stephen Hemminger @ 2026-10-01 18:37 UTC (permalink / raw)
To: netdev; +Cc: Stephen Hemminger
If realloc in the getcommandline failed then the previous
partial command line would leak.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
lib/utils.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/lib/utils.c b/lib/utils.c
index 6388d981..c4cd3c3d 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -1368,6 +1368,8 @@ static ssize_t getcmdline(char **linep, size_t *lenp, FILE *in)
char *line1 = NULL;
size_t len1 = 0;
ssize_t cc1;
+ char *line2;
+ size_t len2;
cc1 = getline(&line1, &len1, in);
if (cc1 < 0) {
@@ -1383,13 +1385,16 @@ static ssize_t getcmdline(char **linep, size_t *lenp, FILE *in)
if (cp)
*cp = '\0';
- *lenp = strlen(*linep) + strlen(line1) + 1;
- *linep = realloc(*linep, *lenp);
- if (!*linep) {
+ len2 = strlen(*linep) + strlen(line1) + 1;
+ line2 = realloc(*linep, len2);
+ if (line2 == NULL) {
fprintf(stderr, "Out of memory\n");
- *lenp = 0;
+ free(line1);
return -1;
}
+ *linep = line2;
+ *lenp = len2;
+
cc += cc1 - 2;
strcat(*linep, line1);
free(line1);
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH iproute] lib: fix leak on realloc() failure
2026-10-01 18:37 [PATCH iproute] lib: fix leak on realloc() failure Stephen Hemminger
@ 2026-10-02 16:00 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-10-02 16:00 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev
Hello:
This patch was applied to iproute2/iproute2.git (main)
by Stephen Hemminger <stephen@networkplumber.org>:
On Thu, 1 Oct 2026 11:37:31 -0700 you wrote:
> If realloc in the getcommandline failed then the previous
> partial command line would leak.
>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
> lib/utils.c | 13 +++++++++----
> 1 file changed, 9 insertions(+), 4 deletions(-)
Here is the summary with links:
- [iproute] lib: fix leak on realloc() failure
https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=e11870d5b941
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [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 18:37 [PATCH iproute] lib: fix leak on realloc() failure Stephen Hemminger
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