diff options
author | cem <cem@FreeBSD.org> | 2016-06-07 20:26:00 +0000 |
---|---|---|
committer | cem <cem@FreeBSD.org> | 2016-06-07 20:26:00 +0000 |
commit | 2b749a1b9244c8ba27478116a8feddc141a1477e (patch) | |
tree | 88f64a35300ef41c5f3c9eb627b8d993c04b0b44 /sys/net | |
parent | d579d254f0908a2cd243a193cccf45a920896d68 (diff) | |
download | FreeBSD-src-2b749a1b9244c8ba27478116a8feddc141a1477e.zip FreeBSD-src-2b749a1b9244c8ba27478116a8feddc141a1477e.tar.gz |
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
Diffstat (limited to 'sys/net')
-rw-r--r-- | sys/net/iflib.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/sys/net/iflib.c b/sys/net/iflib.c index b7dd3ac..955a1b2 100644 --- a/sys/net/iflib.c +++ b/sys/net/iflib.c @@ -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 @@ err_tx_desc: 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); } |