summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Yanok <yanok@emcraft.com>2009-08-12 16:42:48 +0400
committerWolfgang Denk <wd@denx.de>2009-08-18 21:30:58 +0200
commitb644006e1a7baa227aedc606ecdf0bb5eeb24cab (patch)
tree05c8d9f1d0a2c1bbe5135d841be32e87a7e8989a
parent7ff66bb0be80cadd681be22a72e5eb02ee14c878 (diff)
downloadu-boot-imx-b644006e1a7baa227aedc606ecdf0bb5eeb24cab.zip
u-boot-imx-b644006e1a7baa227aedc606ecdf0bb5eeb24cab.tar.gz
u-boot-imx-b644006e1a7baa227aedc606ecdf0bb5eeb24cab.tar.bz2
jffs2: clean the cache in case of malloc fails in build_lists
We should call jffs2_clean_cache() if we return from jffs2_build_lists() with an error to prevent usage of incomplete lists. Also we should free() a local buffer to prevent memory leaks. Signed-off-by: Ilya Yanok <yanok@emcraft.com>
-rw-r--r--fs/jffs2/jffs2_1pass.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/fs/jffs2/jffs2_1pass.c b/fs/jffs2/jffs2_1pass.c
index 8c9e2eb..b61a6f9 100644
--- a/fs/jffs2/jffs2_1pass.c
+++ b/fs/jffs2/jffs2_1pass.c
@@ -1457,6 +1457,8 @@ jffs2_1pass_build_lists(struct part_info * part)
if (!sumptr) {
putstr("Can't get memory for summary "
"node!\n");
+ free(buf);
+ jffs2_free_cache(part);
return 0;
}
memcpy(sumptr + sumlen - buf_len, buf +
@@ -1478,8 +1480,11 @@ jffs2_1pass_build_lists(struct part_info * part)
if (buf_size && sumlen > buf_size)
free(sumptr);
- if (ret < 0)
+ if (ret < 0) {
+ free(buf);
+ jffs2_free_cache(part);
return 0;
+ }
if (ret)
continue;
@@ -1592,8 +1597,11 @@ jffs2_1pass_build_lists(struct part_info * part)
break;
if (insert_node(&pL->frag, (u32) part->offset +
- ofs) == NULL)
+ ofs) == NULL) {
+ free(buf);
+ jffs2_free_cache(part);
return 0;
+ }
if (max_totlen < node->totlen)
max_totlen = node->totlen;
break;
@@ -1619,8 +1627,11 @@ jffs2_1pass_build_lists(struct part_info * part)
if (! (counterN%100))
puts ("\b\b. ");
if (insert_node(&pL->dir, (u32) part->offset +
- ofs) == NULL)
+ ofs) == NULL) {
+ free(buf);
+ jffs2_free_cache(part);
return 0;
+ }
if (max_totlen < node->totlen)
max_totlen = node->totlen;
counterN++;