From e6811c51c63fb2438c8293e7734c02e4c84da0e5 Mon Sep 17 00:00:00 2001 From: Lukas Sismis Date: Tue, 25 Mar 2025 12:31:48 +0100 Subject: [PATCH] dpdk: NULL freed variables The DPDKDeviceResourcesDeinit function now accepts second-level reference to NULL the provided variable after deinitialization.. --- src/runmode-dpdk.c | 5 +++-- src/util-dpdk-common.c | 23 ++++++++++++----------- src/util-dpdk-common.h | 2 +- src/util-dpdk.c | 2 +- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/runmode-dpdk.c b/src/runmode-dpdk.c index e1b071721a..f13e27d006 100644 --- a/src/runmode-dpdk.c +++ b/src/runmode-dpdk.c @@ -336,7 +336,7 @@ static void DPDKDerefConfig(void *conf) DPDKIfaceConfig *iconf = (DPDKIfaceConfig *)conf; if (SC_ATOMIC_SUB(iconf->ref, 1) == 1) { - DPDKDeviceResourcesDeinit(iconf->pkt_mempools); + DPDKDeviceResourcesDeinit(&iconf->pkt_mempools); SCFree(iconf); } SCReturn; @@ -1464,6 +1464,7 @@ static int DeviceConfigureQueues(DPDKIfaceConfig *iconf, const struct rte_eth_de if (retval < 0) { SCLogError("%s: failed to setup TX queue %u: %s", iconf->iface, queue_id, rte_strerror(-retval)); + retval = -1; // the error code explained, informing about failure goto cleanup; } } @@ -1471,7 +1472,7 @@ static int DeviceConfigureQueues(DPDKIfaceConfig *iconf, const struct rte_eth_de SCReturnInt(0); cleanup: - DPDKDeviceResourcesDeinit(iconf->pkt_mempools); + DPDKDeviceResourcesDeinit(&iconf->pkt_mempools); SCReturnInt(retval); } diff --git a/src/util-dpdk-common.c b/src/util-dpdk-common.c index 5ef967b141..52b8d77060 100644 --- a/src/util-dpdk-common.c +++ b/src/util-dpdk-common.c @@ -47,21 +47,22 @@ int DPDKDeviceResourcesInit(DPDKDeviceResources **dpdk_vars, uint16_t mp_cnt) SCReturnInt(0); } -void DPDKDeviceResourcesDeinit(DPDKDeviceResources *dpdk_vars) +void DPDKDeviceResourcesDeinit(DPDKDeviceResources **dpdk_vars) { - if (dpdk_vars != NULL) { - if (dpdk_vars->pkt_mp != NULL) { - for (int j = 0; j < dpdk_vars->pkt_mp_capa; j++) { - if (dpdk_vars->pkt_mp[j] != NULL) { - rte_mempool_free(dpdk_vars->pkt_mp[j]); + if ((*dpdk_vars) != NULL) { + if ((*dpdk_vars)->pkt_mp != NULL) { + for (int j = 0; j < (*dpdk_vars)->pkt_mp_capa; j++) { + if ((*dpdk_vars)->pkt_mp[j] != NULL) { + rte_mempool_free((*dpdk_vars)->pkt_mp[j]); } } - SCFree(dpdk_vars->pkt_mp); - dpdk_vars->pkt_mp_capa = 0; - dpdk_vars->pkt_mp_cnt = 0; - dpdk_vars->pkt_mp = NULL; + SCFree((*dpdk_vars)->pkt_mp); + (*dpdk_vars)->pkt_mp_capa = 0; + (*dpdk_vars)->pkt_mp_cnt = 0; + (*dpdk_vars)->pkt_mp = NULL; } - SCFree(dpdk_vars); + SCFree(*dpdk_vars); + *dpdk_vars = NULL; } } diff --git a/src/util-dpdk-common.h b/src/util-dpdk-common.h index 9a2779dc7c..0caa2ac371 100644 --- a/src/util-dpdk-common.h +++ b/src/util-dpdk-common.h @@ -124,7 +124,7 @@ typedef struct { } DPDKDeviceResources; int DPDKDeviceResourcesInit(DPDKDeviceResources **dpdk_vars, uint16_t mp_cnt); -void DPDKDeviceResourcesDeinit(DPDKDeviceResources *dpdk_vars); +void DPDKDeviceResourcesDeinit(DPDKDeviceResources **dpdk_vars); #endif /* HAVE_DPDK */ diff --git a/src/util-dpdk.c b/src/util-dpdk.c index 22ac12efc1..09e05ccd0e 100644 --- a/src/util-dpdk.c +++ b/src/util-dpdk.c @@ -60,7 +60,7 @@ void DPDKFreeDevice(LiveDevice *ldev) #ifdef HAVE_DPDK if (SCRunmodeGet() == RUNMODE_DPDK) { SCLogDebug("%s: releasing packet mempools", ldev->dev); - DPDKDeviceResourcesDeinit(ldev->dpdk_vars); + DPDKDeviceResourcesDeinit(&ldev->dpdk_vars); } #endif }