From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id E3DD358CB for ; Mon, 9 Mar 2015 07:39:00 +0100 (CET) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP; 08 Mar 2015 23:38:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,366,1422950400"; d="scan'208";a="464469807" Received: from pgsmsx106.gar.corp.intel.com ([10.221.44.98]) by FMSMGA003.fm.intel.com with ESMTP; 08 Mar 2015 23:32:22 -0700 Received: from shsmsx102.ccr.corp.intel.com (10.239.4.154) by PGSMSX106.gar.corp.intel.com (10.221.44.98) with Microsoft SMTP Server (TLS) id 14.3.195.1; Mon, 9 Mar 2015 14:38:52 +0800 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.192]) by shsmsx102.ccr.corp.intel.com ([169.254.2.62]) with mapi id 14.03.0195.001; Mon, 9 Mar 2015 14:38:50 +0800 From: "Qiu, Michael" To: "Ouyang, Changchun" , "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH v4] af_packet: Fix some klocwork errors Thread-Index: AQHQWhwWJOlkgpPpM0KSEnQeHpMpdg== Date: Mon, 9 Mar 2015 06:38:49 +0000 Message-ID: <533710CFB86FA344BFBF2D6802E60286CF065F@SHSMSX101.ccr.corp.intel.com> References: <1425086874-6238-1-git-send-email-changchun.ouyang@intel.com> <1425872941-26481-1-git-send-email-changchun.ouyang@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v4] 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: Mon, 09 Mar 2015 06:39:01 -0000 On 3/9/2015 11:49 AM, Ouyang Changchun wrote:=0A= > Fix possible memory leak issue: free kvlist before return;=0A= > Fix possible resource lost issue: close qssockfd before return;=0A= >=0A= > Signed-off-by: Changchun Ouyang =0A= > ---=0A= > Change in v4:=0A= > - Check sockfd in internals->rx_queue against 0.=0A= >=0A= > Change in v3:=0A= > - Also close sockets for all queues.=0A= > =0A= > Change in v2:=0A= > - Make the error exit point a common path.=0A= >=0A= > lib/librte_pmd_af_packet/rte_eth_af_packet.c | 14 ++++++++++++--=0A= > 1 file changed, 12 insertions(+), 2 deletions(-)=0A= >=0A= > diff --git a/lib/librte_pmd_af_packet/rte_eth_af_packet.c b/lib/librte_pm= d_af_packet/rte_eth_af_packet.c=0A= > index 80e9bdf..acdf408 100644=0A= > --- a/lib/librte_pmd_af_packet/rte_eth_af_packet.c=0A= > +++ b/lib/librte_pmd_af_packet/rte_eth_af_packet.c=0A= > @@ -691,9 +691,14 @@ error:=0A= > rte_free((*internals)->rx_queue[q].rd);=0A= > if ((*internals)->tx_queue[q].rd)=0A= > rte_free((*internals)->tx_queue[q].rd);=0A= > + if (((*internals)->rx_queue[q].sockfd !=3D 0) &&=0A= > + ((*internals)->rx_queue[q].sockfd !=3D qsockfd))=0A= > + close((*internals)->rx_queue[q].sockfd);=0A= > }=0A= > rte_free(*internals);=0A= > }=0A= > + if (qsockfd !=3D -1)=0A= =0A= Hi, Ouyang=0A= =0A= qsockfd was first initialized:=0A= for (q =3D 0; q < nb_queues; q++) {=0A= /* Open an AF_PACKET socket for this queue... */=0A= qsockfd =3D socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));= =0A= =0A= What will happen if gets an error before here, is there any issue? I=0A= think better to initialize it when declare it.=0A= =0A= Thanks,=0A= Michael=0A= > + close(qsockfd);=0A= > return -1;=0A= > }=0A= > =0A= > @@ -823,16 +828,21 @@ rte_pmd_af_packet_devinit(const char *name, const c= har *params)=0A= > ret =3D rte_kvargs_process(kvlist, ETH_AF_PACKET_IFACE_ARG,=0A= > &open_packet_iface, &sockfd);=0A= > if (ret < 0)=0A= > - return -1;=0A= > + goto error;=0A= > }=0A= > =0A= > ret =3D rte_eth_from_packet(name, &sockfd, numa_node, kvlist);=0A= > close(sockfd); /* no longer needed */=0A= > =0A= > if (ret < 0)=0A= > - return -1;=0A= > + goto error;=0A= > =0A= > + rte_kvargs_free(kvlist);=0A= > return 0;=0A= > +=0A= > +error:=0A= > + rte_kvargs_free(kvlist);=0A= > + return -1;=0A= > }=0A= > =0A= > static struct rte_driver pmd_af_packet_drv =3D {=0A= =0A=