Selaa lähdekoodia

UBIFS: Fix possible memory leak in ubifs_readdir()

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>
Richard Weinberger 9 vuotta sitten
vanhempi
commit
aeeb14f763
1 muutettua tiedostoa jossa 3 lisäystä ja 2 poistoa
  1. 3 2
      fs/ubifs/dir.c

+ 3 - 2
fs/ubifs/dir.c

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