From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id C51C4594E for ; Thu, 12 Mar 2015 11:43:28 +0100 (CET) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP; 12 Mar 2015 03:43:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,387,1422950400"; d="scan'208";a="697681394" Received: from kmsmsx151.gar.corp.intel.com ([172.21.73.86]) by orsmga002.jf.intel.com with ESMTP; 12 Mar 2015 03:43:26 -0700 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by KMSMSX151.gar.corp.intel.com (172.21.73.86) with Microsoft SMTP Server (TLS) id 14.3.195.1; Thu, 12 Mar 2015 18:43:25 +0800 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.150]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.228]) with mapi id 14.03.0224.002; Thu, 12 Mar 2015 18:43:24 +0800 From: "Qiu, Michael" To: "Ouyang, Changchun" , "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH v7] af_packet: Fix some klocwork errors Thread-Index: AQHQW5uLtbh3V4/laUG/rqBOhgtpJA== Date: Thu, 12 Mar 2015 10:43:24 +0000 Message-ID: <533710CFB86FA344BFBF2D6802E60286D02B43@SHSMSX101.ccr.corp.intel.com> References: <1425958188-25041-1-git-send-email-changchun.ouyang@intel.com> <1426037641-4515-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 v7] 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: Thu, 12 Mar 2015 10:43:29 -0000 On 3/11/2015 9:34 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 v7:=0A= > - Remove unnecessary '!=3D NULL' check before freeing it; =0A= >=0A= > Change in v6:=0A= > - Refine exit point;=0A= > =0A= > Change in v5:=0A= > - Initialize qsockfd with -1;=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= Acked-by: Michael Qiu =0A= > lib/librte_pmd_af_packet/rte_eth_af_packet.c | 25 ++++++++++++++++------= ---=0A= > 1 file changed, 16 insertions(+), 9 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..2ac50ba 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= > @@ -442,7 +442,8 @@ rte_pmd_init_internals(const char *name,=0A= > struct tpacket_req *req;=0A= > struct pkt_rx_queue *rx_queue;=0A= > struct pkt_tx_queue *tx_queue;=0A= > - int rc, qsockfd, tpver, discard;=0A= > + int rc, tpver, discard;=0A= > + int qsockfd =3D -1;=0A= > unsigned int i, q, rdsize;=0A= > int fanout_arg __rte_unused, bypass __rte_unused;=0A= > =0A= > @@ -691,9 +692,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= > + close(qsockfd);=0A= > return -1;=0A= > }=0A= > =0A= > @@ -802,7 +808,7 @@ int=0A= > rte_pmd_af_packet_devinit(const char *name, const char *params)=0A= > {=0A= > unsigned numa_node;=0A= > - int ret;=0A= > + int ret =3D 0;=0A= > struct rte_kvargs *kvlist;=0A= > int sockfd =3D -1;=0A= > =0A= > @@ -811,8 +817,10 @@ rte_pmd_af_packet_devinit(const char *name, const ch= ar *params)=0A= > numa_node =3D rte_socket_id();=0A= > =0A= > kvlist =3D rte_kvargs_parse(params, valid_arguments);=0A= > - if (kvlist =3D=3D NULL)=0A= > - return -1;=0A= > + if (kvlist =3D=3D NULL) {=0A= > + ret =3D -1;=0A= > + goto exit;=0A= > + }=0A= > =0A= > /*=0A= > * If iface argument is passed we open the NICs and use them for=0A= > @@ -823,16 +831,15 @@ 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 exit;=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= > -=0A= > - return 0;=0A= > +exit:=0A= > + rte_kvargs_free(kvlist);=0A= > + return ret;=0A= > }=0A= > =0A= > static struct rte_driver pmd_af_packet_drv =3D {=0A= =0A=