UBIFS: Fix possible memory leak in ubifs_readdir()
authorRichard Weinberger <richard@nod.at>
Mon, 12 Oct 2015 21:35:36 +0000 (23:35 +0200)
committerRichard Weinberger <richard@nod.at>
Fri, 6 Nov 2015 22:26:49 +0000 (23:26 +0100)
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>
fs/ubifs/dir.c

index 1dd9267..a2f9d97 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;