DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] app/testpmd: fix memory leak in port attach
@ 2025-12-02  9:57 Shani Peretz
  0 siblings, 0 replies; only message in thread
From: Shani Peretz @ 2025-12-02  9:57 UTC (permalink / raw)
  To: dev
  Cc: stephen, Shani Peretz, stable, Aman Singh, Gregory Etelson,
	Dariusz Sosnowski

The convert_pci_address_format() function was leaking memory because
rte_devargs_parse() allocates memory internally via strdup(), but the
function never called rte_devargs_reset() to free it.

Add a cleanup label to ensure rte_devargs_reset() is called on all
return paths.

Fixes: 12c2405989f6 ("app/testpmd: canonicalize short PCI name format")
Fixes: acbff64ea5b1 ("app/testpmd: fix devargs format in port attach")
Cc: stable@dpdk.org

Signed-off-by: Shani Peretz <shperetz@nvidia.com>
---
 app/test-pmd/testpmd.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 1fe41d852a..7c8cd44013 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -3433,23 +3433,28 @@ convert_pci_address_format(const char *identifier, char *pci_buffer, size_t buf_
 	struct rte_devargs da;
 	struct rte_pci_addr pci_addr;
 	size_t pci_len;
+	char *result = NULL;
 
 	if (rte_devargs_parse(&da, identifier) != 0)
 		return NULL;
 
 	if (da.bus == NULL)
-		return NULL;
+		goto cleanup;
 
 	if (strcmp(rte_bus_name(da.bus), "pci") != 0)
-		return NULL;
+		goto cleanup;
 
 	if (rte_pci_addr_parse(da.name, &pci_addr) != 0)
-		return NULL;
+		goto cleanup;
 
 	rte_pci_device_name(&pci_addr, pci_buffer, buf_size);
 	pci_len = strlen(pci_buffer);
 	snprintf(pci_buffer + pci_len, buf_size - pci_len, ",%s", da.args);
-	return pci_buffer;
+	result = pci_buffer;
+
+cleanup:
+	rte_devargs_reset(&da);
+	return result;
 }
 
 void
-- 
2.43.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-12-02  9:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-02  9:57 [PATCH] app/testpmd: fix memory leak in port attach Shani Peretz

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).