jffs2: clean the cache in case of malloc fails in build_lists
PATCH 1/1 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 <[email protected]>
--- fs/jffs2/jffs2_1pass.c | 17 ++++++++++++++--- 1 files changed, 14 insertions(+), 3 deletions(-)
fs/jffs2/jffs2_1pass.c +14 -3
@@ -1496,6 +1496,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 +
@@ -1517,8 +1519,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 ;
@@ -1632,8 +1637,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 ;
@@ -1659,8 +1667,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++;
Signature · 1 line
1.6.0.6
Wolfgang Denk
AppliedPATCH 1/1 jffs2: clean the cache in case of malloc fails in build_lists
Dear Ilya Yanok,
Quoted 8 lines · In message <[email protected]> you wrote:
We should call
jffs2_clean_cache()if we return fromjffs2_build_lists()with an error to prevent usage of incomplete lists. Also we shouldfree()a local buffer to prevent memory leaks.Signed-off-by Ilya Yanok <[email protected]>--- fs/jffs2/jffs2_1pass.c | 17 ++++++++++++++--- 1 files changed, 14 insertions(+), 3 deletions(-)
Applied, thanks.
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de "The trouble with doing something right the first time is that nobody appreciates how difficult it was." - Walt West