From: Daniel van Gerpen <daniel@vangerpen.de>
To: linux-mtd@lists.infradead.org
Subject: [PATCH] Fix memory leaks found by clang's static analyzer
Date: Mon, 31 Mar 2014 22:06:53 +0200 [thread overview]
Message-ID: <20140331220653.5b26c11e@abel> (raw)
Signed-off-by: Daniel van Gerpen <daniel@vangerpen.de>
---
ftl_format.c | 4 ++++
lib/libmtd.c | 1 +
mkfs.ubifs/devtable.c | 12 ++++++++----
3 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/ftl_format.c b/ftl_format.c
index b58677f..80144d4 100644
--- a/ftl_format.c
+++ b/ftl_format.c
@@ -190,6 +190,7 @@ static int format_partition(int fd, int quiet, int interrogate,
fflush(stdout);
}
perror("block erase failed");
+ free(bam);
return -1;
}
erase.start += erase.length;
@@ -245,6 +246,9 @@ static int format_partition(int fd, int quiet, int interrogate,
break;
}
}
+
+ free(bam);
+
if (i < le16_to_cpu(hdr.NumEraseUnits))
return -1;
else
diff --git a/lib/libmtd.c b/lib/libmtd.c
index 2089373..6b83832 100644
--- a/lib/libmtd.c
+++ b/lib/libmtd.c
@@ -1113,6 +1113,7 @@ static int legacy_auto_oob_layout(const struct mtd_dev_info *mtd, int fd,
memcpy(oob + start, tmp_buf + start, len);
}
+ free(tmp_buf);
return 0;
}
diff --git a/mkfs.ubifs/devtable.c b/mkfs.ubifs/devtable.c
index dee035d..1ab242e 100644
--- a/mkfs.ubifs/devtable.c
+++ b/mkfs.ubifs/devtable.c
@@ -213,8 +213,10 @@ static int interpret_table_entry(const char *line)
}
}
- if (increment != 0 && count == 0)
- return err_msg("count cannot be zero if increment is non-zero");
+ if (increment != 0 && count == 0) {
+ err_msg("count cannot be zero if increment is non-zero");
+ goto out_free;
+ }
/*
* Add the file/directory/device node (last component of the path) to
@@ -239,8 +241,10 @@ static int interpret_table_entry(const char *line)
dbg_msg(3, "inserting '%s' into name hash table (major %d, minor %d)",
name, major(nh_elt->dev), minor(nh_elt->dev));
- if (hashtable_search(ph_elt->name_htbl, name))
- return err_msg("'%s' is referred twice", buf);
+ if (hashtable_search(ph_elt->name_htbl, name)) {
+ err_msg("'%s' is referred twice", buf);
+ goto out_free;
+ }
nh_elt->name = name;
if (!hashtable_insert(ph_elt->name_htbl, name, nh_elt)) {
--
1.8.3.2
reply other threads:[~2014-03-31 20:07 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20140331220653.5b26c11e@abel \
--to=daniel@vangerpen.de \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox