lib: fix leak on realloc() failure
Subsystems (3)
PATCH 1/1 lib: fix leak on realloc() failure
If realloc in the getcommandline failed then the previous partial command line would leak.
Signed-off-by Stephen Hemminger <[email protected]>
--- lib/utils.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
lib/utils.c +9 -4
@@ -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);
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 7 lines · 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 <[email protected]>--- 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!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html