Skip to contentSkip to conversation

nbd: don't leak nbd_config

PATCH In review Ilya Dryomov 3 participants 5 messages May 23, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nbd: don't leak nbd_config

nbd_config is allocated in nbd_alloc_config(), but never freed.

Fixes 5ea8d10802ec ("nbd: separate out the config information")
---
 drivers/block/nbd.c | 1 +
 1 file changed, 1 insertion(+)
drivers/block/nbd.c +1 -0
index 9a7bb2c29447..882fb9efbab1 100644
@@ -940,6 +940,7 @@ static int nbd_reconnect_socket(struct nbd_device *nbd, unsigned long arg)
 /* Reset all properties of an NBD device */
 static void nbd_reset(struct nbd_device *nbd)
 {
+	kfree(nbd->config);
 	nbd->config = NULL;
 	nbd->tag_set.timeout = 0;
 	queue_flag_clear_unlocked(QUEUE_FLAG_DISCARD, nbd->disk->queue);
Signature · 1 line
2.4.3
#2 lore raw
Quoted 10 lines · Josef Bacik
Quoted 8 lines · Ilya Dryomov

nbd_config is allocated in nbd_alloc_config(), but never freed.

Fixes 5ea8d10802ec ("nbd: separate out the config information")
---
 drivers/block/nbd.c | 1 +
 1 file changed, 1 insertion(+)
Quoted 3 lines

Oops, thanks Ilya

Since config is referenced, why isn't this done in nbd_config_put() instead?

Signature · 1 line
Jens Axboe
#3 lore raw
Quoted 11 lines · Jens Axboe
Quoted 10 lines · Josef Bacik
Quoted 8 lines · Ilya Dryomov

nbd_config is allocated in nbd_alloc_config(), but never freed.

Fixes 5ea8d10802ec ("nbd: separate out the config information")
---
 drivers/block/nbd.c | 1 +
 1 file changed, 1 insertion(+)
Quoted 6 lines
Quoted 3 lines

Oops, thanks Ilya

Since config is referenced, why isn't this done in nbd_config_put() instead?

Josef's 5ea8d10802ec added that nbd->config = NULL to nbd_reset(), so I followed his lead. It could be done nbd_config_put() -- nbd_reset() call in nbd_dev_add() looks like a no-op to me. Josef?

Thanks,

Ilya

maintainer
#4 lore raw
Quoted 14 lines · Ilya Dryomov
Quoted 13 lines · Jens Axboe
Quoted 12 lines · Josef Bacik
Quoted 8 lines · Ilya Dryomov

nbd_config is allocated in nbd_alloc_config(), but never freed.

Fixes 5ea8d10802ec ("nbd: separate out the config information")
---
 drivers/block/nbd.c | 1 +
 1 file changed, 1 insertion(+)

Oops, thanks Ilya

Quoted 9 lines
Quoted 4 lines
Quoted 1 line

Since config is referenced, why isn't this done in nbd_config_put() instead?

Josef's 5ea8d10802ec added that nbd->config = NULL to nbd_reset(), so I followed his lead. It could be done nbd_config_put() -- nbd_reset() call in nbd_dev_add() looks like a no-op to me. Josef?

Yeah it used to be called more, but when I moved the config to be ref counted it lost it's old uses and I just didn't notice enough to delete it. Just fold that into nbd_config_put() and call it a day. Thanks,

Josef