From owner-svn-src-all@freebsd.org Tue Jun 7 20:26:01 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id DC29EB6E3F7; Tue, 7 Jun 2016 20:26:01 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 9169E198B; Tue, 7 Jun 2016 20:26:01 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u57KQ0M8042360; Tue, 7 Jun 2016 20:26:00 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u57KQ0FR042359; Tue, 7 Jun 2016 20:26:00 GMT (envelope-from cem@FreeBSD.org) Message-Id: <201606072026.u57KQ0FR042359@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: "Conrad E. Meyer" Date: Tue, 7 Jun 2016 20:26:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r301567 - head/sys/net X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Jun 2016 20:26:02 -0000 Author: cem Date: Tue Jun 7 20:26:00 2016 New Revision: 301567 URL: https://svnweb.freebsd.org/changeset/base/301567 Log: 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 Modified: head/sys/net/iflib.c Modified: head/sys/net/iflib.c ============================================================================== --- head/sys/net/iflib.c Tue Jun 7 20:16:01 2016 (r301566) +++ head/sys/net/iflib.c Tue Jun 7 20:26:00 2016 (r301567) @@ -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); }