[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20201119100428.GA14090@e121166-lin.cambridge.arm.com>
Date: Thu, 19 Nov 2020 10:04:28 +0000
From: Lorenzo Pieralisi <lorenzo.pieralisi@....com>
To: Peng Fan <fanpeng@...ngson.cn>
Cc: Kishon Vijay Abraham I <kishon@...com>, linux-pci@...r.kernel.org,
linux-kernel@...r.kernel.org, Xuefeng Li <lixuefeng@...ngson.cn>,
Tiezhu Yang <yangtiezhu@...ngson.cn>
Subject: Re: [PATCH] tools: PCI: Fix memory leak in run_test
On Thu, Jun 11, 2020 at 07:32:46PM +0800, Peng Fan wrote:
> We should free "test" before the return of run_test.
>
> Signed-off-by: Peng Fan <fanpeng@...ngson.cn>
> ---
> tools/pci/pcitest.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/tools/pci/pcitest.c b/tools/pci/pcitest.c
> index 0a1344c..7c20332 100644
> --- a/tools/pci/pcitest.c
> +++ b/tools/pci/pcitest.c
> @@ -47,6 +47,7 @@ static int run_test(struct pci_test *test)
> fd = open(test->device, O_RDWR);
> if (fd < 0) {
> perror("can't open PCI Endpoint Test device");
> + free(test);
> return -ENODEV;
> }
>
> @@ -151,6 +152,7 @@ static int run_test(struct pci_test *test)
>
> fflush(stdout);
> close(fd);
> + free(test);
> return (ret < 0) ? ret : 1 - ret; /* return 0 if test succeeded */
> }
>
> --
> 2.1.0
This is not necessary, though good practice but I would do it when
run_test() returns not as you did.
Patch dropped, feel free to resend it.
Lorenzo
Powered by blists - more mailing lists