[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <af7a5219-76e7-4d1e-b05f-9674919abc62@huawei.com>
Date: Thu, 22 Aug 2024 11:29:19 +0800
From: Zheng Qixing <zhengqixing@...wei.com>
To: Zheng Qixing <zhengqixing@...weicloud.com>, <dlemoal@...nel.org>
CC: <linux-ide@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<yukuai3@...wei.com>, <yi.zhang@...wei.com>, <yangerkun@...wei.com>
Subject: Re: [PATCH] ata:Fix memory leak for error path in ata_host_alloc()
在 2024/8/22 11:17, Zheng Qixing 写道:
> From: Zheng Qixing <zhengqixing@...wei.com>
>
> In ata_host_alloc(), if ata_port_alloc(host) fails to allocate memory
> for a port, the allocated 'host' structure is not freed before returning
> from the function. This results in a potential memory leak.
>
> This patch adds a kfree(host) before the error handling code is executed
> to ensure that the 'host' structure is properly freed in case of an
> allocation failure.
>
> Signed-off-by: Zheng Qixing <zhengqixing@...wei.com>
> ---
> drivers/ata/libata-core.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
> index ee18c09c39b6..cb3ace759699 100644
> --- a/drivers/ata/libata-core.c
> +++ b/drivers/ata/libata-core.c
> @@ -5610,9 +5610,10 @@ struct ata_host *ata_host_alloc(struct device *dev, int max_ports)
> struct ata_port *ap;
>
> ap = ata_port_alloc(host);
> - if (!ap)
> + if (!ap) {
> kfree(host);
> goto err_out;
> + }
>
> ap->port_no = i;
> host->ports[i] = ap;
Sorry, this patch is wrong, i will send a new version.
Zheng Qixing
Powered by blists - more mailing lists