patches for DPDK stable branches
 help / color / mirror / Atom feed
* [dpdk-stable] [PATCH] mem: fix resource leak
@ 2018-10-22 12:57 Anatoly Burakov
  2018-10-22 20:34 ` [dpdk-stable] [dpdk-dev] " Thomas Monjalon
  0 siblings, 1 reply; 3+ messages in thread
From: Anatoly Burakov @ 2018-10-22 12:57 UTC (permalink / raw)
  To: dev; +Cc: stable

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 <anatoly.burakov@intel.com>
---

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-10-23  9:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-22 12:57 [dpdk-stable] [PATCH] mem: fix resource leak Anatoly Burakov
2018-10-22 20:34 ` [dpdk-stable] [dpdk-dev] " Thomas Monjalon
2018-10-23  9:37   ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).