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: [email protected]

Signed-off-by: Shani Peretz <[email protected]>
---
 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

Reply via email to