From: Artem Bityutskiy Date: Fri, 6 May 2011 14:08:56 +0000 (+0300) Subject: UBIFS: fix a rare memory leak in ro to rw remounting path X-Git-Tag: v3.0-rc1~317^2~26 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=eaeee242c531cd4b0a4a46e8b5dd7ef504380c42;p=linux-block.git UBIFS: fix a rare memory leak in ro to rw remounting path When re-mounting from R/O mode to R/W mode and the LEB count in the superblock is not up-to date, because for the underlying UBI volume became larger, we re-write the superblock. We allocate RAM for these purposes, but never free it. So this is a memory leak, although very rare one. Signed-off-by: Artem Bityutskiy Cc: stable@kernel.org --- diff --git a/fs/ubifs/sb.c b/fs/ubifs/sb.c index bf31b4729e51..cad60b51f7c4 100644 --- a/fs/ubifs/sb.c +++ b/fs/ubifs/sb.c @@ -475,7 +475,8 @@ failed: * @c: UBIFS file-system description object * * This function returns a pointer to the superblock node or a negative error - * code. + * code. Note, the user of this function is responsible of kfree()'ing the + * returned superblock buffer. */ struct ubifs_sb_node *ubifs_read_sb_node(struct ubifs_info *c) { diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c index 407c064fb1c1..575ea8353d08 100644 --- a/fs/ubifs/super.c +++ b/fs/ubifs/super.c @@ -1585,6 +1585,7 @@ static int ubifs_remount_rw(struct ubifs_info *c) } sup->leb_cnt = cpu_to_le32(c->leb_cnt); err = ubifs_write_sb_node(c, sup); + kfree(sup); if (err) goto out; }