tools: PCI: Fix memory leak in run_test
diff mbox series

Message ID 1591875166-12243-1-git-send-email-fanpeng@loongson.cn
State New
Delegated to: Lorenzo Pieralisi
Headers show
Series
  • tools: PCI: Fix memory leak in run_test
Related show

Commit Message

Peng Fan June 11, 2020, 11:32 a.m. UTC
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(+)

Patch
diff mbox series

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 */
 }