[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <8eaec334781e695810aaa383b55de00ca4ab1352.1703439383.git.christophe.jaillet@wanadoo.fr>
Date: Sun, 24 Dec 2023 18:36:42 +0100
From: Christophe JAILLET <christophe.jaillet@...adoo.fr>
To: Jens Axboe <axboe@...nel.dk>,
Jan Kara <jack@...e.cz>,
Christian Brauner <brauner@...nel.org>
Cc: linux-kernel@...r.kernel.org,
kernel-janitors@...r.kernel.org,
Christophe JAILLET <christophe.jaillet@...adoo.fr>,
linux-block@...r.kernel.org
Subject: [PATCH] block: Fix a memory leak in bdev_open_by_dev()
If we early exit here, 'handle' needs to be freed, or some memory leaks.
Fixes: ed5cc702d311 ("block: Add config option to not allow writing to mounted devices")
Signed-off-by: Christophe JAILLET <christophe.jaillet@...adoo.fr>
---
The code could also be re-arranged to delay the memory allocation.
This would be cleaner IMHO.
---
block/bdev.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/block/bdev.c b/block/bdev.c
index 6f73b02d549c..e9f1b12bd75c 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -830,8 +830,10 @@ struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,
goto free_handle;
/* Blocking writes requires exclusive opener */
- if (mode & BLK_OPEN_RESTRICT_WRITES && !holder)
- return ERR_PTR(-EINVAL);
+ if (mode & BLK_OPEN_RESTRICT_WRITES && !holder) {
+ ret = -EINVAL;
+ goto free_handle;
+ }
bdev = blkdev_get_no_open(dev);
if (!bdev) {
--
2.34.1
Powered by blists - more mailing lists