linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tools: PCI: Fix memory leak in run_test
@ 2020-06-11 11:32 Peng Fan
  2020-11-19 10:04 ` Lorenzo Pieralisi
  0 siblings, 1 reply; 2+ messages in thread
From: Peng Fan @ 2020-06-11 11:32 UTC (permalink / raw)
  To: Kishon Vijay Abraham I, Lorenzo Pieralisi
  Cc: linux-pci, linux-kernel, Xuefeng Li, Tiezhu Yang

We should free "test" before the return of run_test.

Signed-off-by: Peng Fan <fanpeng@loongson.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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] tools: PCI: Fix memory leak in run_test
  2020-06-11 11:32 [PATCH] tools: PCI: Fix memory leak in run_test Peng Fan
@ 2020-11-19 10:04 ` Lorenzo Pieralisi
  0 siblings, 0 replies; 2+ messages in thread
From: Lorenzo Pieralisi @ 2020-11-19 10:04 UTC (permalink / raw)
  To: Peng Fan
  Cc: Kishon Vijay Abraham I, linux-pci, linux-kernel, Xuefeng Li, Tiezhu Yang

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@loongson.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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-11-19 10:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-11 11:32 [PATCH] tools: PCI: Fix memory leak in run_test Peng Fan
2020-11-19 10:04 ` Lorenzo Pieralisi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).