linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
To: Peng Fan <fanpeng@loongson.cn>
Cc: Kishon Vijay Abraham I <kishon@ti.com>,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
	Xuefeng Li <lixuefeng@loongson.cn>,
	Tiezhu Yang <yangtiezhu@loongson.cn>
Subject: Re: [PATCH] tools: PCI: Fix memory leak in run_test
Date: Thu, 19 Nov 2020 10:04:28 +0000	[thread overview]
Message-ID: <20201119100428.GA14090@e121166-lin.cambridge.arm.com> (raw)
In-Reply-To: <1591875166-12243-1-git-send-email-fanpeng@loongson.cn>

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

      reply	other threads:[~2020-11-19 10:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-11 11:32 [PATCH] tools: PCI: Fix memory leak in run_test Peng Fan
2020-11-19 10:04 ` Lorenzo Pieralisi [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201119100428.GA14090@e121166-lin.cambridge.arm.com \
    --to=lorenzo.pieralisi@arm.com \
    --cc=fanpeng@loongson.cn \
    --cc=kishon@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lixuefeng@loongson.cn \
    --cc=yangtiezhu@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).