Message ID | 20240514205525.28342-2-ant.v.moryakov@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Delegated to: | David Ahern |
Headers | show |
Series | utils.c: Fixed potential memory leak in getcmdline function | expand |
Context | Check | Description |
---|---|---|
netdev/tree_selection | success | Not a local patch |
diff --git a/lib/utils.c b/lib/utils.c index 051cff9c..d46b47fb 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -1339,6 +1339,9 @@ 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"); + if (line1) { + free(line1); + } return cc1; }
The getcmdline function in utils.c dynamically allocates memory for the line1 variable using getline function but fails to free it in case of an error. Added a check to free the allocated memory if getline returns a negative value, preventing potential memory leaks. Signed-off-by: Anton ant.v.moryakov@gmail.com --- lib/utils.c | 3 +++ 1 file changed, 3 insertions(+)