提交 b644006e 编写于 作者: I Ilya Yanok 提交者: Wolfgang Denk

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: NIlya Yanok <yanok@emcraft.com>
上级 7ff66bb0
...@@ -1457,6 +1457,8 @@ jffs2_1pass_build_lists(struct part_info * part) ...@@ -1457,6 +1457,8 @@ jffs2_1pass_build_lists(struct part_info * part)
if (!sumptr) { if (!sumptr) {
putstr("Can't get memory for summary " putstr("Can't get memory for summary "
"node!\n"); "node!\n");
free(buf);
jffs2_free_cache(part);
return 0; return 0;
} }
memcpy(sumptr + sumlen - buf_len, buf + memcpy(sumptr + sumlen - buf_len, buf +
...@@ -1478,8 +1480,11 @@ jffs2_1pass_build_lists(struct part_info * part) ...@@ -1478,8 +1480,11 @@ jffs2_1pass_build_lists(struct part_info * part)
if (buf_size && sumlen > buf_size) if (buf_size && sumlen > buf_size)
free(sumptr); free(sumptr);
if (ret < 0) if (ret < 0) {
free(buf);
jffs2_free_cache(part);
return 0; return 0;
}
if (ret) if (ret)
continue; continue;
...@@ -1592,8 +1597,11 @@ jffs2_1pass_build_lists(struct part_info * part) ...@@ -1592,8 +1597,11 @@ jffs2_1pass_build_lists(struct part_info * part)
break; break;
if (insert_node(&pL->frag, (u32) part->offset + if (insert_node(&pL->frag, (u32) part->offset +
ofs) == NULL) ofs) == NULL) {
free(buf);
jffs2_free_cache(part);
return 0; return 0;
}
if (max_totlen < node->totlen) if (max_totlen < node->totlen)
max_totlen = node->totlen; max_totlen = node->totlen;
break; break;
...@@ -1619,8 +1627,11 @@ jffs2_1pass_build_lists(struct part_info * part) ...@@ -1619,8 +1627,11 @@ jffs2_1pass_build_lists(struct part_info * part)
if (! (counterN%100)) if (! (counterN%100))
puts ("\b\b. "); puts ("\b\b. ");
if (insert_node(&pL->dir, (u32) part->offset + if (insert_node(&pL->dir, (u32) part->offset +
ofs) == NULL) ofs) == NULL) {
free(buf);
jffs2_free_cache(part);
return 0; return 0;
}
if (max_totlen < node->totlen) if (max_totlen < node->totlen)
max_totlen = node->totlen; max_totlen = node->totlen;
counterN++; counterN++;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册