From mboxrd@z Thu Jan 1 00:00:00 1970 From: Pablo de Lara Subject: [PATCH 2/2] test/hash: fix potential memory leak Date: Tue, 17 Jul 2018 14:31:51 +0100 Message-ID: <20180717133151.30065-2-pablo.de.lara.guarch@intel.com> References: <20180717133151.30065-1-pablo.de.lara.guarch@intel.com> Cc: dev@dpdk.org, Pablo de Lara , stable@dpdk.org To: bruce.richardson@intel.com Return-path: In-Reply-To: <20180717133151.30065-1-pablo.de.lara.guarch@intel.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" In the multiwriter test, if "found" array allocation failed, the memory of "keys" array, which was successfully allocated could not be freed, since by this time, tbl_multiwriter_test_params.keys was not set to this array, which is the pointer freed when finishing the test or when a failure happens. To solve this, tbl_multiwriter_test_params.keys is set to the "keys" address, just after allocating and filling the array. Fixes: be856325cba3 ("hash: add scalable multi-writer insertion with Intel TSX") Cc: stable@dpdk.org Signed-off-by: Pablo de Lara --- test/test/test_hash_multiwriter.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/test/test_hash_multiwriter.c b/test/test/test_hash_multiwriter.c index acd6a91ca..6a3eb10bd 100644 --- a/test/test/test_hash_multiwriter.c +++ b/test/test/test_hash_multiwriter.c @@ -154,16 +154,17 @@ test_hash_multiwriter(void) goto err1; } + for (i = 0; i < nb_entries; i++) + keys[i] = i; + + tbl_multiwriter_test_params.keys = keys; + found = rte_zmalloc(NULL, sizeof(uint32_t) * nb_entries, 0); if (found == NULL) { printf("RTE_ZMALLOC failed\n"); goto err2; } - for (i = 0; i < nb_entries; i++) - keys[i] = i; - - tbl_multiwriter_test_params.keys = keys; tbl_multiwriter_test_params.found = found; rte_atomic64_init(&gcycles); -- 2.14.4