From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by dpdk.org (Postfix) with ESMTP id D8F804C9F; Mon, 22 Oct 2018 14:57:05 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Oct 2018 05:57:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,412,1534834800"; d="scan'208";a="274530995" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga006.fm.intel.com with ESMTP; 22 Oct 2018 05:57:04 -0700 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id w9MCv39p004480; Mon, 22 Oct 2018 13:57:03 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id w9MCv3mn027516; Mon, 22 Oct 2018 13:57:03 +0100 Received: (from aburakov@localhost) by sivswdev01.ir.intel.com with LOCAL id w9MCv3LX027512; Mon, 22 Oct 2018 13:57:03 +0100 From: Anatoly Burakov To: dev@dpdk.org Cc: stable@dpdk.org Date: Mon, 22 Oct 2018 13:57:03 +0100 Message-Id: <9183826f1b6f3bb3d80cdde12fbd59f07f4df348.1540212745.git.anatoly.burakov@intel.com> X-Mailer: git-send-email 1.7.0.7 Subject: [dpdk-dev] [PATCH] mem: 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: Mon, 22 Oct 2018 12:57:06 -0000 Segment preallocation code allocates an array of structures on the heap but does not free the memory afterwards. Fix it by freeing it at the end of the function, and changing control flow to always go through that code path. Fixes: 1dd342d0fdc4 ("mem: improve segment list preallocation") Coverity ID: 323524 Cc: stable@dpdk.org Signed-off-by: Anatoly Burakov --- Notes: Not sure if stable release script picks up fixes for commits intended for stable releases? lib/librte_eal/linuxapp/eal/eal_memory.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c index 19e686eb6..fce86fda6 100644 --- a/lib/librte_eal/linuxapp/eal/eal_memory.c +++ b/lib/librte_eal/linuxapp/eal/eal_memory.c @@ -2135,7 +2135,7 @@ memseg_primary_init(void) uint64_t page_sz; int socket_id; } *memtypes = NULL; - int i, hpi_idx, msl_idx; + int i, hpi_idx, msl_idx, ret = -1; /* fail unless told to succeed */ struct rte_memseg_list *msl; uint64_t max_mem, max_mem_per_type; unsigned int max_seglists_per_type; @@ -2227,7 +2227,7 @@ memseg_primary_init(void) if (max_seglists_per_type == 0) { RTE_LOG(ERR, EAL, "Cannot accommodate all memory types, please increase %s\n", RTE_STR(CONFIG_RTE_MAX_MEMSEG_LISTS)); - return -1; + goto out; } /* go through all mem types and create segment lists */ @@ -2287,21 +2287,25 @@ memseg_primary_init(void) RTE_LOG(ERR, EAL, "No more space in memseg lists, please increase %s\n", RTE_STR(CONFIG_RTE_MAX_MEMSEG_LISTS)); - return -1; + goto out; } msl = &mcfg->memsegs[msl_idx++]; if (alloc_memseg_list(msl, pagesz, n_segs, socket_id, cur_seglist)) - return -1; + goto out; if (alloc_va_space(msl)) { RTE_LOG(ERR, EAL, "Cannot allocate VA space for memseg list\n"); - return -1; + goto out; } } } - return 0; + /* we're successful */ + ret = 0; +out: + free(memtypes); + return ret; } static int -- 2.17.1