jffs2: fix a memleak in read_direntry()

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Fri Nov 6 10:59:10 PST 2015


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=eb042ec35956de2684de2a05a814cd15efe570ca
Commit:     eb042ec35956de2684de2a05a814cd15efe570ca
Parent:     d54e88011d0a5fb48d9bb60fede3e83375c75841
Author:     Wei Fang <fangwei1 at huawei.com>
AuthorDate: Tue Sep 29 11:23:55 2015 +0800
Committer:  Brian Norris <computersforpeace at gmail.com>
CommitDate: Sun Oct 4 22:30:50 2015 +0100

    jffs2: fix a memleak in read_direntry()
    
    Need to free the memory allocated for 'fd' if failed to read all
    of the remainder name.
    
    Signed-off-by: Wei Fang <fangwei1 at huawei.com>
    Signed-off-by: Brian Norris <computersforpeace at gmail.com>
---
 fs/jffs2/readinode.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/fs/jffs2/readinode.c b/fs/jffs2/readinode.c
index 28e0aab..bfebbf1 100644
--- a/fs/jffs2/readinode.c
+++ b/fs/jffs2/readinode.c
@@ -660,8 +660,12 @@ static inline int read_direntry(struct jffs2_sb_info *c, struct jffs2_raw_node_r
 
 		err = jffs2_flash_read(c, (ref_offset(ref)) + read,
 				rd->nsize - already, &read, &fd->name[already]);
-		if (unlikely(read != rd->nsize - already) && likely(!err))
+		if (unlikely(read != rd->nsize - already) && likely(!err)) {
+			jffs2_free_full_dirent(fd);
+			JFFS2_ERROR("short read: wanted %d bytes, got %zd\n",
+				    rd->nsize - already, read);
 			return -EIO;
+		}
 
 		if (unlikely(err)) {
 			JFFS2_ERROR("read remainder of name: error %d\n", err);



More information about the linux-mtd-cvs mailing list