From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.tuxdriver.com (charlotte.tuxdriver.com [70.61.120.58]) by dpdk.org (Postfix) with ESMTP id 0D84B7E6A for ; Fri, 27 Feb 2015 15:04:36 +0100 (CET) Received: from hmsreliant.think-freely.org ([2001:470:8:a08:7aac:c0ff:fec2:933b] helo=localhost) by smtp.tuxdriver.com with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.63) (envelope-from ) id 1YRLWq-0008FP-Ng; Fri, 27 Feb 2015 09:04:34 -0500 Date: Fri, 27 Feb 2015 09:04:31 -0500 From: Neil Horman To: Ouyang Changchun Message-ID: <20150227140431.GC1611@hmsreliant.think-freely.org> References: <1424932947-14750-1-git-send-email-changchun.ouyang@intel.com> <1424998153-22718-1-git-send-email-changchun.ouyang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1424998153-22718-1-git-send-email-changchun.ouyang@intel.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Score: -2.9 (--) X-Spam-Status: No Cc: dev@dpdk.org Subject: Re: [dpdk-dev] [PATCH v2] af_packet: Fix some klocwork errors X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Feb 2015 14:04:36 -0000 On Fri, Feb 27, 2015 at 08:49:13AM +0800, Ouyang Changchun wrote: > Fix possible memory leak issue: free kvlist before return; > Fix possible resource lost issue: close qssockfd before return; > > Signed-off-by: Changchun Ouyang > --- > change in v2: > - Make the error exit point a common path. > > lib/librte_pmd_af_packet/rte_eth_af_packet.c | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) > > diff --git a/lib/librte_pmd_af_packet/rte_eth_af_packet.c b/lib/librte_pmd_af_packet/rte_eth_af_packet.c > index 80e9bdf..c675724 100644 > --- a/lib/librte_pmd_af_packet/rte_eth_af_packet.c > +++ b/lib/librte_pmd_af_packet/rte_eth_af_packet.c > @@ -694,6 +694,8 @@ error: > } > rte_free(*internals); > } > + if (qsockfd != -1) > + close(qsockfd); This is insufficient. qsockfd is a loop index that is reassigned for each tx queue we have. In the error path you need to do this, and loop through the tx queues, closing each tx_queue->sockfd. > return -1; > } > > @@ -823,16 +825,21 @@ rte_pmd_af_packet_devinit(const char *name, const char *params) > ret = rte_kvargs_process(kvlist, ETH_AF_PACKET_IFACE_ARG, > &open_packet_iface, &sockfd); > if (ret < 0) > - return -1; > + goto error; > } > > ret = rte_eth_from_packet(name, &sockfd, numa_node, kvlist); > close(sockfd); /* no longer needed */ > > if (ret < 0) > - return -1; > + goto error; > > + rte_kvargs_free(kvlist); > return 0; > + > +error: > + rte_kvargs_free(kvlist); > + return -1; > } > > static struct rte_driver pmd_af_packet_drv = { > -- > 1.8.4.2 > >