iflib: Improve cleanup on iflib_queues_alloc error path

Fix some memory leaks.  Some may remain.

Reported by:	Coverity
Discussed with:	mmacy
CIDs:		1356036, 1356037, 1356038
Sponsored by:	EMC / Isilon Storage Division
This commit is contained in:
Conrad Meyer 2016-06-07 20:26:00 +00:00
parent ab8316b8df
commit 0d0338afc9

View File

@ -3863,6 +3863,9 @@ iflib_queues_alloc(if_ctx_t ctx)
KASSERT(ntxqs > 0, ("number of queues must be at least 1"));
KASSERT(nrxqs > 0, ("number of queues must be at least 1"));
brscp = NULL;
rxq = NULL;
/* Allocate the TX ring struct memory */
if (!(txq =
(iflib_txq_t) malloc(sizeof(struct iflib_txq) *
@ -3888,6 +3891,8 @@ iflib_queues_alloc(if_ctx_t ctx)
ctx->ifc_txqs = txq;
ctx->ifc_rxqs = rxq;
txq = NULL;
rxq = NULL;
/*
* XXX handle allocation failure
@ -3898,7 +3903,7 @@ iflib_queues_alloc(if_ctx_t ctx)
if ((ifdip = malloc(sizeof(struct iflib_dma_info) * ntxqs, M_IFLIB, M_WAITOK|M_ZERO)) == NULL) {
device_printf(dev, "failed to allocate iflib_dma_info\n");
err = ENOMEM;
goto fail;
goto err_tx_desc;
}
txq->ift_ifdi = ifdip;
for (j = 0; j < ntxqs; j++, ifdip++) {
@ -3940,7 +3945,7 @@ iflib_queues_alloc(if_ctx_t ctx)
if (err) {
/* XXX free any allocated rings */
device_printf(dev, "Unable to allocate buf_ring\n");
goto fail;
goto err_tx_desc;
}
}
}
@ -3951,7 +3956,7 @@ iflib_queues_alloc(if_ctx_t ctx)
if ((ifdip = malloc(sizeof(struct iflib_dma_info) * nrxqs, M_IFLIB, M_WAITOK|M_ZERO)) == NULL) {
device_printf(dev, "failed to allocate iflib_dma_info\n");
err = ENOMEM;
goto fail;
goto err_tx_desc;
}
rxq->ifr_ifdi = ifdip;
@ -3975,7 +3980,7 @@ iflib_queues_alloc(if_ctx_t ctx)
(iflib_fl_t) malloc(sizeof(struct iflib_fl) * nfree_lists, M_IFLIB, M_NOWAIT | M_ZERO))) {
device_printf(dev, "Unable to allocate free list memory\n");
err = ENOMEM;
goto fail;
goto err_tx_desc;
}
rxq->ifr_fl = fl;
for (j = 0; j < nfree_lists; j++) {
@ -4042,10 +4047,16 @@ iflib_queues_alloc(if_ctx_t ctx)
if (ctx->ifc_rxqs != NULL)
free(ctx->ifc_rxqs, M_IFLIB);
ctx->ifc_rxqs = NULL;
rx_fail:
if (ctx->ifc_txqs != NULL)
free(ctx->ifc_txqs, M_IFLIB);
ctx->ifc_txqs = NULL;
rx_fail:
if (brscp != NULL)
free(brscp, M_IFLIB);
if (rxq != NULL)
free(rxq, M_IFLIB);
if (txq != NULL)
free(txq, M_IFLIB);
fail:
return (err);
}