Netdev Archive mirror
 help / color / mirror / Atom feed
From: Anton <ant.v.moryakov@gmail.com>
To: stephen@networkplumber.org
Cc: netdev@vger.kernel.org, Anton <ant.v.moryakov@gmail.com>
Subject: [PATCH] utils.c: Fixed potential memory leak in getcmdline function
Date: Tue, 14 May 2024 23:55:25 +0300	[thread overview]
Message-ID: <20240514205525.28342-2-ant.v.moryakov@gmail.com> (raw)
In-Reply-To: <20240514205525.28342-1-ant.v.moryakov@gmail.com>

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(+)

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;
 		}
 
-- 
2.43.0


      reply	other threads:[~2024-05-14 20:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-14 20:55 [PATCH] ila_common.h: Remove redundant check for neutral-map-auto in ila_csum_name2mode function Anton
2024-05-14 20:55 ` Anton [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240514205525.28342-2-ant.v.moryakov@gmail.com \
    --to=ant.v.moryakov@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).