UBIFS: Fix possible memory leak in ubifs_readdir()
authorRichard Weinberger <richard@nod.at>
Mon, 12 Oct 2015 21:35:36 +0000 (23:35 +0200)
committerSasha Levin <alexander.levin@verizon.com>
Thu, 24 Nov 2016 00:58:29 +0000 (19:58 -0500)
[ Upstream commit aeeb14f763917ccf639a602cfbeee6957fd944a2 ]

If ubifs_tnc_next_ent() returns something else than -ENOENT
we leak file->private_data.

Signed-off-by: Richard Weinberger <richard@nod.at>
Reviewed-by: David Gstir <david@sigma-star.at>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
fs/ubifs/dir.c

index 27060fc855d42549b2bbe7d3cbe6329858e3fb2c..4af40ed5e795fe0fe848f2445d870bb073b244e4 100644 (file)
@@ -449,13 +449,14 @@ static int ubifs_readdir(struct file *file, struct dir_context *ctx)
        }
 
 out:
+       kfree(file->private_data);
+       file->private_data = NULL;
+
        if (err != -ENOENT) {
                ubifs_err(c, "cannot find next direntry, error %d", err);
                return err;
        }
 
-       kfree(file->private_data);
-       file->private_data = NULL;
        /* 2 is a special value indicating that there are no more direntries */
        ctx->pos = 2;
        return 0;