test/table: fix memory leak
authorAnatoly Burakov <anatoly.burakov@intel.com>
Tue, 6 Feb 2018 13:35:41 +0000 (13:35 +0000)
committerThomas Monjalon <thomas@monjalon.net>
Tue, 6 Feb 2018 18:45:29 +0000 (19:45 +0100)
Always deallocate allocated resources after the test is done.

Fixes: 5205954791cb ("app/test: packet framework unit tests")
Cc: stable@dpdk.org
Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
test/test/test_table.c

index c9268a3..f01652d 100644 (file)
@@ -54,6 +54,14 @@ uint64_t pipeline_test_hash(void *key,
        return signature;
 }
 
+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)
 {
@@ -113,18 +121,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++) {
@@ -132,8 +142,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;
                }
        }
 
@@ -143,8 +153,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;
                }
        }
 
@@ -154,21 +164,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);