All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anton Moryakov <ant.v.moryakov@gmail.com>
To: linux-mtd@lists.infradead.org
Cc: david.oberhollenzer@sigma-star.at,
	Anton Moryakov <ant.v.moryakov@gmail.com>,
	Zhihao Cheng <chengzhihao1@huawei.com>
Subject: [PATCH] ubifs-utils: common: fix memory leak in devtable.c
Date: Thu, 15 May 2025 11:25:15 +0300	[thread overview]
Message-ID: <20250515082515.1666-1-ant.v.moryakov@gmail.com> (raw)

Report of the static analyzer:
Dynamic memory, referenced by 'line', is allocated at devtable.c:356 
by calling function 'getline' and lost at devtable.c:388. 
(line: while (getline(&line, &len, f) != -1) {)

Correct explained:
Now line is freed in any exit scenario via out_close which eliminates this error.

Triggers found by static analyzer Svace.

Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>

---
 ubifs-utils/common/devtable.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/ubifs-utils/common/devtable.c b/ubifs-utils/common/devtable.c
index 7347f09..2e581ff 100644
--- a/ubifs-utils/common/devtable.c
+++ b/ubifs-utils/common/devtable.c
@@ -392,6 +392,7 @@ int parse_devtable(const char *tbl_file)
 
 out_close:
 	fclose(f);
+	free(line);
 	free_devtable_info();
 	return -1;
 }
--
2.34.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

             reply	other threads:[~2025-05-15  8:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-15  8:25 Anton Moryakov [this message]
2025-06-02  5:35 ` [PATCH] ubifs-utils: common: fix memory leak in devtable.c David Oberhollenzer
  -- strict thread matches above, loose matches on Subject: below --
2025-04-24 18:19 ant.v.moryakov
2025-04-25  3:22 ` Zhihao Cheng

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=20250515082515.1666-1-ant.v.moryakov@gmail.com \
    --to=ant.v.moryakov@gmail.com \
    --cc=chengzhihao1@huawei.com \
    --cc=david.oberhollenzer@sigma-star.at \
    --cc=linux-mtd@lists.infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.