dpdk: NULL freed variables

The DPDKDeviceResourcesDeinit function now accepts second-level
reference to NULL the provided variable after deinitialization..
pull/12888/head
Lukas Sismis 3 months ago committed by Victor Julien
parent fbe5ce7a2b
commit e6811c51c6

@ -336,7 +336,7 @@ static void DPDKDerefConfig(void *conf)
DPDKIfaceConfig *iconf = (DPDKIfaceConfig *)conf; DPDKIfaceConfig *iconf = (DPDKIfaceConfig *)conf;
if (SC_ATOMIC_SUB(iconf->ref, 1) == 1) { if (SC_ATOMIC_SUB(iconf->ref, 1) == 1) {
DPDKDeviceResourcesDeinit(iconf->pkt_mempools); DPDKDeviceResourcesDeinit(&iconf->pkt_mempools);
SCFree(iconf); SCFree(iconf);
} }
SCReturn; SCReturn;
@ -1464,6 +1464,7 @@ static int DeviceConfigureQueues(DPDKIfaceConfig *iconf, const struct rte_eth_de
if (retval < 0) { if (retval < 0) {
SCLogError("%s: failed to setup TX queue %u: %s", iconf->iface, queue_id, SCLogError("%s: failed to setup TX queue %u: %s", iconf->iface, queue_id,
rte_strerror(-retval)); rte_strerror(-retval));
retval = -1; // the error code explained, informing about failure
goto cleanup; goto cleanup;
} }
} }
@ -1471,7 +1472,7 @@ static int DeviceConfigureQueues(DPDKIfaceConfig *iconf, const struct rte_eth_de
SCReturnInt(0); SCReturnInt(0);
cleanup: cleanup:
DPDKDeviceResourcesDeinit(iconf->pkt_mempools); DPDKDeviceResourcesDeinit(&iconf->pkt_mempools);
SCReturnInt(retval); SCReturnInt(retval);
} }

@ -47,21 +47,22 @@ int DPDKDeviceResourcesInit(DPDKDeviceResources **dpdk_vars, uint16_t mp_cnt)
SCReturnInt(0); SCReturnInt(0);
} }
void DPDKDeviceResourcesDeinit(DPDKDeviceResources *dpdk_vars) void DPDKDeviceResourcesDeinit(DPDKDeviceResources **dpdk_vars)
{ {
if (dpdk_vars != NULL) { if ((*dpdk_vars) != NULL) {
if (dpdk_vars->pkt_mp != NULL) { if ((*dpdk_vars)->pkt_mp != NULL) {
for (int j = 0; j < dpdk_vars->pkt_mp_capa; j++) { for (int j = 0; j < (*dpdk_vars)->pkt_mp_capa; j++) {
if (dpdk_vars->pkt_mp[j] != NULL) { if ((*dpdk_vars)->pkt_mp[j] != NULL) {
rte_mempool_free(dpdk_vars->pkt_mp[j]); rte_mempool_free((*dpdk_vars)->pkt_mp[j]);
} }
} }
SCFree(dpdk_vars->pkt_mp); SCFree((*dpdk_vars)->pkt_mp);
dpdk_vars->pkt_mp_capa = 0; (*dpdk_vars)->pkt_mp_capa = 0;
dpdk_vars->pkt_mp_cnt = 0; (*dpdk_vars)->pkt_mp_cnt = 0;
dpdk_vars->pkt_mp = NULL; (*dpdk_vars)->pkt_mp = NULL;
} }
SCFree(dpdk_vars); SCFree(*dpdk_vars);
*dpdk_vars = NULL;
} }
} }

@ -124,7 +124,7 @@ typedef struct {
} DPDKDeviceResources; } DPDKDeviceResources;
int DPDKDeviceResourcesInit(DPDKDeviceResources **dpdk_vars, uint16_t mp_cnt); int DPDKDeviceResourcesInit(DPDKDeviceResources **dpdk_vars, uint16_t mp_cnt);
void DPDKDeviceResourcesDeinit(DPDKDeviceResources *dpdk_vars); void DPDKDeviceResourcesDeinit(DPDKDeviceResources **dpdk_vars);
#endif /* HAVE_DPDK */ #endif /* HAVE_DPDK */

@ -60,7 +60,7 @@ void DPDKFreeDevice(LiveDevice *ldev)
#ifdef HAVE_DPDK #ifdef HAVE_DPDK
if (SCRunmodeGet() == RUNMODE_DPDK) { if (SCRunmodeGet() == RUNMODE_DPDK) {
SCLogDebug("%s: releasing packet mempools", ldev->dev); SCLogDebug("%s: releasing packet mempools", ldev->dev);
DPDKDeviceResourcesDeinit(ldev->dpdk_vars); DPDKDeviceResourcesDeinit(&ldev->dpdk_vars);
} }
#endif #endif
} }

Loading…
Cancel
Save