2018-12-27 14:40:37

by Wenwen Wang

[permalink] [raw]
Subject: [PATCH] gdrom: fix a memory leak bug

In probe_gdrom(), the buffer pointed by 'gd.cd_info' is allocated through
kzalloc() and is used to hold the information of the gdrom device. To
register and unregister the device, the pointer 'gd.cd_info' is passed to
the functions register_cdrom() and unregister_cdrom(), respectively.
However, this buffer is not freed after it is used, which can cause a
memory leak bug.

This patch simply frees the buffer 'gd.cd_info' in exit_gdrom() to fix the
above issue.

Signed-off-by: Wenwen Wang <[email protected]>
---
drivers/cdrom/gdrom.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
index a5b8afe..f8b7345 100644
--- a/drivers/cdrom/gdrom.c
+++ b/drivers/cdrom/gdrom.c
@@ -873,6 +873,7 @@ static void __exit exit_gdrom(void)
platform_device_unregister(pd);
platform_driver_unregister(&gdrom_driver);
kfree(gd.toc);
+ kfree(gd.cd_info);
}

module_init(init_gdrom);
--
2.7.4



2018-12-29 22:04:21

by Jens Axboe

[permalink] [raw]
Subject: Re: [PATCH] gdrom: fix a memory leak bug

On 12/26/18 7:15 PM, Wenwen Wang wrote:
> In probe_gdrom(), the buffer pointed by 'gd.cd_info' is allocated through
> kzalloc() and is used to hold the information of the gdrom device. To
> register and unregister the device, the pointer 'gd.cd_info' is passed to
> the functions register_cdrom() and unregister_cdrom(), respectively.
> However, this buffer is not freed after it is used, which can cause a
> memory leak bug.
>
> This patch simply frees the buffer 'gd.cd_info' in exit_gdrom() to fix the
> above issue.

Applied, thanks.

--
Jens Axboe