From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id 0C46F1BB1B; Fri, 27 Oct 2017 17:08:35 +0200 (CEST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP; 27 Oct 2017 08:08:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,304,1505804400"; d="scan'208";a="168468592" Received: from irsmsx106.ger.corp.intel.com ([163.33.3.31]) by fmsmga006.fm.intel.com with ESMTP; 27 Oct 2017 08:08:21 -0700 Received: from irsmsx109.ger.corp.intel.com ([169.254.13.28]) by IRSMSX106.ger.corp.intel.com ([169.254.8.36]) with mapi id 14.03.0319.002; Fri, 27 Oct 2017 16:08:21 +0100 From: "Jastrzebski, MichalX K" To: "Piasecki, JacekX" , "Dumitrescu, Cristian" CC: "dev@dpdk.org" , "Piasecki, JacekX" , "stable@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH] cfgfile: fix resource leak Thread-Index: AQHTTiLfv5f0HhRmOkmzQqFRvJ3vT6L3zhOw Date: Fri, 27 Oct 2017 15:08:19 +0000 Message-ID: <60ABE07DBB3A454EB7FAD707B4BB158213C4B1B1@IRSMSX109.ger.corp.intel.com> References: <1508998869-4963-1-git-send-email-jacekx.piasecki@intel.com> In-Reply-To: <1508998869-4963-1-git-send-email-jacekx.piasecki@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.0.0.116 dlp-reaction: no-action x-ctpclassification: CTP_IC x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMjhmY2Y2NDEtOWY3ZC00NjBmLThhMjQtMjFlMDRkMmU1MDA4IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE2LjUuOS4zIiwiVHJ1c3RlZExhYmVsSGFzaCI6IkY3VGhJNkpXRTZoK3Y4RlYwM3VZQnBQSmhaWkRiMWwzRzQ3TGh0TzdhMkk9In0= x-originating-ip: [163.33.239.181] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH] cfgfile: fix resource leak X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Oct 2017 15:08:36 -0000 > -----Original Message----- > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Jacek Piasecki > Sent: Thursday, October 26, 2017 8:21 AM > To: Dumitrescu, Cristian > Cc: dev@dpdk.org; Piasecki, JacekX ; > stable@dpdk.org > Subject: [dpdk-dev] [PATCH] cfgfile: fix resource leak >=20 > Unsuccesfull memory allocation for elements inside cfgfile > structure could result in resource leak. > Fixed by pointer verification after each malloc, > if malloc fail - error branch is proceeded with freeing memory. >=20 > Coverity issue: 195032 > Fixes: d4cb8197589d ("cfgfile: support runtime modification") > Cc: jacekx.piasecki@intel.com > Cc: stable@dpdk.org >=20 > Signed-off-by: Jacek Piasecki > --- > lib/librte_cfgfile/rte_cfgfile.c | 18 ++++++++++++++++-- > 1 file changed, 16 insertions(+), 2 deletions(-) >=20 > diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cf= gfile.c > index 124aef5..2880b9a 100644 > --- a/lib/librte_cfgfile/rte_cfgfile.c > +++ b/lib/librte_cfgfile/rte_cfgfile.c > @@ -298,7 +298,7 @@ rte_cfgfile_create(int flags) > CFG_ALLOC_SECTION_BATCH); >=20 > if (cfg->sections =3D=3D NULL) > - return NULL; > + goto error1; >=20 > cfg->allocated_sections =3D CFG_ALLOC_SECTION_BATCH; >=20 > @@ -307,7 +307,7 @@ rte_cfgfile_create(int flags) > struct rte_cfgfile_entry) * > CFG_ALLOC_ENTRY_BATCH); >=20 > if (cfg->sections[i].entries =3D=3D NULL) > - return NULL; > + goto error1; >=20 > cfg->sections[i].num_entries =3D 0; > cfg->sections[i].allocated_entries =3D > CFG_ALLOC_ENTRY_BATCH; > @@ -315,7 +315,21 @@ rte_cfgfile_create(int flags) >=20 > if (flags & CFG_FLAG_GLOBAL_SECTION) > rte_cfgfile_add_section(cfg, "GLOBAL"); > + > return cfg; > +error1: > + if (cfg->sections !=3D NULL) { > + for (i =3D 0; i < cfg->allocated_sections; i++) { > + if (cfg->sections[i].entries !=3D NULL) { > + free(cfg->sections[i].entries); > + cfg->sections[i].entries =3D NULL; > + } > + } > + free(cfg->sections); > + cfg->sections =3D NULL; > + } > + free(cfg); > + return NULL; > } >=20 > int > -- > 2.7.4 Acked-by: Michal Jastrzebski