DPDK patches and discussions
 help / color / mirror / Atom feed
From: Shani Peretz <shperetz@nvidia.com>
To: <dev@dpdk.org>
Cc: <stephen@networkplumber.org>, Shani Peretz <shperetz@nvidia.com>,
	<stable@dpdk.org>, Aman Singh <aman.deep.singh@intel.com>,
	Gregory Etelson <getelson@nvidia.com>,
	Dariusz Sosnowski <dsosnowski@nvidia.com>
Subject: [PATCH] app/testpmd: fix memory leak in port attach
Date: Tue, 2 Dec 2025 11:57:20 +0200	[thread overview]
Message-ID: <20251202095720.264195-1-shperetz@nvidia.com> (raw)

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


                 reply	other threads:[~2025-12-02  9:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20251202095720.264195-1-shperetz@nvidia.com \
    --to=shperetz@nvidia.com \
    --cc=aman.deep.singh@intel.com \
    --cc=dev@dpdk.org \
    --cc=dsosnowski@nvidia.com \
    --cc=getelson@nvidia.com \
    --cc=stable@dpdk.org \
    --cc=stephen@networkplumber.org \
    /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).