All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heinrich Schuchardt <xypron.glpk@gmx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/1] fs: fat: memory leak in fat_unlink()
Date: Tue,  2 Oct 2018 06:58:00 +0200	[thread overview]
Message-ID: <20181002045800.19361-1-xypron.glpk@gmx.de> (raw)

Do not leak filename_copy in case of error.
Catch out of memory when calling strdup.

This addresses Coverity Scan CID 184086.

Reported-by: Tom Rini <trini@konsulko.com>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
 fs/fat/fat_write.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
index 4286a0a847..b1ed0e6734 100644
--- a/fs/fat/fat_write.c
+++ b/fs/fat/fat_write.c
@@ -1263,6 +1263,11 @@ int fat_unlink(const char *filename)
 	char *filename_copy, *dirname, *basename;
 
 	filename_copy = strdup(filename);
+	if (!filename_copy) {
+		printf("Error: allocating memory\n");
+		ret = -ENOMEM;
+		goto exit;
+	}
 	split_filename(filename_copy, &dirname, &basename);
 
 	if (!strcmp(dirname, "/") && !strcmp(basename, "")) {
@@ -1274,7 +1279,8 @@ int fat_unlink(const char *filename)
 	itr = malloc_cache_aligned(sizeof(fat_itr));
 	if (!itr) {
 		printf("Error: allocating memory\n");
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto exit;
 	}
 
 	ret = fat_itr_root(itr, &fsdata);
-- 
2.19.0

             reply	other threads:[~2018-10-02  4:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-02  4:58 Heinrich Schuchardt [this message]
2018-10-02  6:39 ` [U-Boot] [PATCH 1/1] fs: fat: memory leak in fat_unlink() AKASHI Takahiro
2018-10-07  0:29 ` [U-Boot] [U-Boot,1/1] " Tom Rini

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=20181002045800.19361-1-xypron.glpk@gmx.de \
    --to=xypron.glpk@gmx.de \
    --cc=u-boot@lists.denx.de \
    /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.