From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (unknown [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id C90A61BA1C; Thu, 26 Oct 2017 08:22:38 +0200 (CEST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Oct 2017 23:22:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,434,1503385200"; d="scan'208";a="1235463815" Received: from gklab-246-073.igk.intel.com (HELO Sent) ([10.217.246.73]) by fmsmga002.fm.intel.com with SMTP; 25 Oct 2017 23:22:34 -0700 Received: by Sent (sSMTP sendmail emulation); Thu, 26 Oct 2017 08:21:23 +0200 From: Jacek Piasecki To: cristian.dumitrescu@intel.com Cc: dev@dpdk.org, Jacek Piasecki , stable@dpdk.org Date: Thu, 26 Oct 2017 08:21:09 +0200 Message-Id: <1508998869-4963-1-git-send-email-jacekx.piasecki@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [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: Thu, 26 Oct 2017 06:22:39 -0000 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. Coverity issue: 195032 Fixes: d4cb8197589d ("cfgfile: support runtime modification") Cc: jacekx.piasecki@intel.com Cc: stable@dpdk.org Signed-off-by: Jacek Piasecki --- lib/librte_cfgfile/rte_cfgfile.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.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); if (cfg->sections == NULL) - return NULL; + goto error1; cfg->allocated_sections = CFG_ALLOC_SECTION_BATCH; @@ -307,7 +307,7 @@ rte_cfgfile_create(int flags) struct rte_cfgfile_entry) * CFG_ALLOC_ENTRY_BATCH); if (cfg->sections[i].entries == NULL) - return NULL; + goto error1; cfg->sections[i].num_entries = 0; cfg->sections[i].allocated_entries = CFG_ALLOC_ENTRY_BATCH; @@ -315,7 +315,21 @@ rte_cfgfile_create(int flags) if (flags & CFG_FLAG_GLOBAL_SECTION) rte_cfgfile_add_section(cfg, "GLOBAL"); + return cfg; +error1: + if (cfg->sections != NULL) { + for (i = 0; i < cfg->allocated_sections; i++) { + if (cfg->sections[i].entries != NULL) { + free(cfg->sections[i].entries); + cfg->sections[i].entries = NULL; + } + } + free(cfg->sections); + cfg->sections = NULL; + } + free(cfg); + return NULL; } int -- 2.7.4