[dpdk-dev,5/6] test: fix memory leak in table autotest

Message ID 31d7534c095b9e6a0e36880f30d666778eff00d8.1513867589.git.anatoly.burakov@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Anatoly Burakov Dec. 22, 2017, 10:12 a.m. UTC
  Always deallocate allocated resources after the test is done.

Fixes: 5205954791cb ("app/test: packet framework unit tests")
Cc: cristian.dumitrescu@intel.com
Cc: stable@dpdk.org
Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 test/test/test_table.c | 44 ++++++++++++++++++++++++++++----------------
 1 file changed, 28 insertions(+), 16 deletions(-)
  

Comments

Cristian Dumitrescu Jan. 11, 2018, 2:17 p.m. UTC | #1
> -----Original Message-----
> From: Burakov, Anatoly
> Sent: Friday, December 22, 2017 10:12 AM
> To: dev@dpdk.org
> Cc: Dumitrescu, Cristian <cristian.dumitrescu@intel.com>; stable@dpdk.org
> Subject: [PATCH 5/6] test: fix memory leak in table autotest
> 
> Always deallocate allocated resources after the test is done.
> 
> Fixes: 5205954791cb ("app/test: packet framework unit tests")
> Cc: cristian.dumitrescu@intel.com
> Cc: stable@dpdk.org
> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
> ---
>  test/test/test_table.c | 44 ++++++++++++++++++++++++++++----------------
>  1 file changed, 28 insertions(+), 16 deletions(-)
> 
> diff --git a/test/test/test_table.c b/test/test/test_table.c


Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
  

Patch

diff --git a/test/test/test_table.c b/test/test/test_table.c
index db7d4e6..c5a6e00 100644
--- a/test/test/test_table.c
+++ b/test/test/test_table.c
@@ -84,6 +84,14 @@  uint64_t pipeline_test_hash(void *key,
 }
 
 static void
+app_free_resources(void) {
+	int i;
+	for (i = 0; i < N_PORTS; i++)
+		rte_ring_free(rings_rx[i]);
+	rte_mempool_free(pool);
+}
+
+static void
 app_init_mbuf_pools(void)
 {
 	/* Init the buffer pool */
@@ -142,18 +150,20 @@  app_init_rings(void)
 static int
 test_table(void)
 {
-	int status, failures;
+	int status, ret;
 	unsigned i;
 
-	failures = 0;
+	ret = TEST_SUCCESS;
 
 	app_init_rings();
 	app_init_mbuf_pools();
 
 	printf("\n\n\n\n************Pipeline tests************\n");
 
-	if (test_table_pipeline() < 0)
-		return -1;
+	if (test_table_pipeline() < 0) {
+		ret = TEST_FAILED;
+		goto end;
+	}
 
 	printf("\n\n\n\n************Port tests************\n");
 	for (i = 0; i < n_port_tests; i++) {
@@ -161,8 +171,8 @@  test_table(void)
 		if (status < 0) {
 			printf("\nPort test number %d failed (%d).\n", i,
 				status);
-			failures++;
-			return -1;
+			ret = TEST_FAILED;
+			goto end;
 		}
 	}
 
@@ -172,8 +182,8 @@  test_table(void)
 		if (status < 0) {
 			printf("\nTable test number %d failed (%d).\n", i,
 				status);
-			failures++;
-			return -1;
+			ret = TEST_FAILED;
+			goto end;
 		}
 	}
 
@@ -183,21 +193,23 @@  test_table(void)
 		if (status < 0) {
 			printf("\nCombined table test number %d failed with "
 				"reason number %d.\n", i, status);
-			failures++;
-			return -1;
+			ret = TEST_FAILED;
+			goto end;
 		}
 	}
 
-	if (failures)
-		return -1;
-
 #ifdef RTE_LIBRTE_ACL
 	printf("\n\n\n\n************ACL tests************\n");
-	if (test_table_acl() < 0)
-		return -1;
+	if (test_table_acl() < 0) {
+		ret = TEST_FAILED;
+		goto end;
+	}
 #endif
 
-	return 0;
+end:
+	app_free_resources();
+
+	return ret;
 }
 
 REGISTER_TEST_COMMAND(table_autotest, test_table);