[PATCH v2 06/11] net/tap: fix resource leaks in tap create error path

Stephen Hemminger
2026-02-16T23:05:25Z

Correct two leaks in eth_dev_tap_create():

- process_private was never freed on error_exit. Add free() before
releasing the port.
- If the process_private malloc failed, the function returned -1
directly without releasing the ethdev port allocated by
rte_eth_vdev_allocate(). Jump to a new error_exit_nodev_release
label instead.

Bugzilla ID: 1881
Fixes: ed8132e7c912 ("net/tap: move fds of queues to be in process private")
Cc: stable@dpdk.org

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
drivers/net/tap/rte_eth_tap.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index 45ca32cfb8..9b38d1f50b 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -2010,7 +2010,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
process_private = malloc(sizeof(struct pmd_process_private));
if (process_private == NULL) {
TAP_LOG(ERR, "Failed to alloc memory for process private");
- return -1;
+ goto error_exit_nodev_release;
}
memset(process_private, 0, sizeof(struct pmd_process_private));

@@ -2200,9 +2200,12 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
close(pmd->nlsk_fd);
if (pmd->ka_fd != -1)
close(pmd->ka_fd);
+ rte_intr_instance_free(pmd->intr_handle);
+ free(dev->process_private);
+
+error_exit_nodev_release:
/* mac_addrs must not be freed alone because part of dev_private */
dev->data->mac_addrs = NULL;
- rte_intr_instance_free(pmd->intr_handle);
rte_eth_dev_release_port(dev);

error_exit_nodev:
--
2.51.0