Skip to contentSkip to conversation

app/testpmd: fix memory leak in port attach

PATCH Applied Shani Peretz 2 participants 2 messages Dec 2, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 app/testpmd: fix memory leak in port attach

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")
---
 app/test-pmd/testpmd.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
app/test-pmd/testpmd.c +9 -4
index 1fe41d852a..7c8cd44013 100644
@@ -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
Signature · 1 line
2.43.0
#1 lore raw
Quoted 4 lines · On Tue, 2 Dec 2025 11:57:20 +0200 Shani Peretz <[email protected]> wrote:

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.

Quoted 8 lines

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

Queued to next-net for 26.03