From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id B7C6E1B62A; Tue, 6 Feb 2018 14:35:46 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Feb 2018 05:35:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,468,1511856000"; d="scan'208";a="201616754" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga005.fm.intel.com with ESMTP; 06 Feb 2018 05:35:43 -0800 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 w16DZhmD012563; Tue, 6 Feb 2018 13:35:43 GMT Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id w16DZh4H011027; Tue, 6 Feb 2018 13:35:43 GMT Received: (from aburakov@localhost) by sivswdev01.ir.intel.com with LOCAL id w16DZg7p011023; Tue, 6 Feb 2018 13:35:42 GMT From: Anatoly Burakov To: dev@dpdk.org Cc: Olivier Matz , pablo.de.lara.guarch@intel.com, stable@dpdk.org Date: Tue, 6 Feb 2018 13:35:39 +0000 Message-Id: X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <662303f9fc36dc3f45ae0f4a6f21eeb91f8f000d.1517917927.git.anatoly.burakov@intel.com> References: <662303f9fc36dc3f45ae0f4a6f21eeb91f8f000d.1517917927.git.anatoly.burakov@intel.com> In-Reply-To: <409be7970a029d2d2cfffeafee43ea2645244eb2.1517834482.git.anatoly.burakov@intel.com> References: <409be7970a029d2d2cfffeafee43ea2645244eb2.1517834482.git.anatoly.burakov@intel.com> Subject: [dpdk-stable] [PATCH v5 3/6] test: fix memory leak in ring autotest X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Feb 2018 13:35:47 -0000 Get rid of global static ring variable and don't reuse rings between test runs. Acked-by: Olivier Matz Fixes: 4e32101f9b01 ("ring: support freeing") Cc: pablo.de.lara.guarch@intel.com Cc: stable@dpdk.org Signed-off-by: Anatoly Burakov --- Notes: v5: fix use of uninitialized pointer v3: fix commit message to point to approriate commit being fixed v2: remove static ring variable test/test/test_ring.c | 63 +++++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/test/test/test_ring.c b/test/test/test_ring.c index 19d497a..aaf1e70 100644 --- a/test/test/test_ring.c +++ b/test/test/test_ring.c @@ -57,8 +57,6 @@ static rte_atomic32_t synchro; -static struct rte_ring *r; - #define TEST_RING_VERIFY(exp) \ if (!(exp)) { \ printf("error at %s:%d\tcondition " #exp " failed\n", \ @@ -73,7 +71,7 @@ static struct rte_ring *r; * helper routine for test_ring_basic */ static int -test_ring_basic_full_empty(void * const src[], void *dst[]) +test_ring_basic_full_empty(struct rte_ring *r, void * const src[], void *dst[]) { unsigned i, rand; const unsigned rsz = RING_SIZE - 1; @@ -114,7 +112,7 @@ test_ring_basic_full_empty(void * const src[], void *dst[]) } static int -test_ring_basic(void) +test_ring_basic(struct rte_ring *r) { void **src = NULL, **cur_src = NULL, **dst = NULL, **cur_dst = NULL; int ret; @@ -250,7 +248,7 @@ test_ring_basic(void) goto fail; } - if (test_ring_basic_full_empty(src, dst) != 0) + if (test_ring_basic_full_empty(r, src, dst) != 0) goto fail; cur_src = src; @@ -317,7 +315,7 @@ test_ring_basic(void) } static int -test_ring_burst_basic(void) +test_ring_burst_basic(struct rte_ring *r) { void **src = NULL, **cur_src = NULL, **dst = NULL, **cur_dst = NULL; int ret; @@ -671,7 +669,7 @@ test_ring_basic_ex(void) { int ret = -1; unsigned i; - struct rte_ring * rp; + struct rte_ring *rp = NULL; void **obj = NULL; obj = rte_calloc("test_ring_basic_ex_malloc", RING_SIZE, sizeof(void *), 0); @@ -731,6 +729,7 @@ test_ring_basic_ex(void) ret = 0; fail_test: + rte_ring_free(rp); if (obj != NULL) rte_free(obj); @@ -811,61 +810,67 @@ test_ring_with_exact_size(void) static int test_ring(void) { + struct rte_ring *r = NULL; + /* some more basic operations */ if (test_ring_basic_ex() < 0) - return -1; + goto test_fail; rte_atomic32_init(&synchro); + r = rte_ring_create("test", RING_SIZE, SOCKET_ID_ANY, 0); if (r == NULL) - r = rte_ring_create("test", RING_SIZE, SOCKET_ID_ANY, 0); - if (r == NULL) - return -1; + goto test_fail; /* retrieve the ring from its name */ if (rte_ring_lookup("test") != r) { printf("Cannot lookup ring from its name\n"); - return -1; + goto test_fail; } /* burst operations */ - if (test_ring_burst_basic() < 0) - return -1; + if (test_ring_burst_basic(r) < 0) + goto test_fail; /* basic operations */ - if (test_ring_basic() < 0) - return -1; + if (test_ring_basic(r) < 0) + goto test_fail; /* basic operations */ if ( test_create_count_odd() < 0){ - printf ("Test failed to detect odd count\n"); - return -1; - } - else - printf ( "Test detected odd count\n"); + printf("Test failed to detect odd count\n"); + goto test_fail; + } else + printf("Test detected odd count\n"); if ( test_lookup_null() < 0){ - printf ("Test failed to detect NULL ring lookup\n"); - return -1; - } - else - printf ( "Test detected NULL ring lookup \n"); + printf("Test failed to detect NULL ring lookup\n"); + goto test_fail; + } else + printf("Test detected NULL ring lookup\n"); /* test of creating ring with wrong size */ if (test_ring_creation_with_wrong_size() < 0) - return -1; + goto test_fail; /* test of creation ring with an used name */ if (test_ring_creation_with_an_used_name() < 0) - return -1; + goto test_fail; if (test_ring_with_exact_size() < 0) - return -1; + goto test_fail; /* dump the ring status */ rte_ring_list_dump(stdout); + rte_ring_free(r); + return 0; + +test_fail: + rte_ring_free(r); + + return -1; } REGISTER_TEST_COMMAND(ring_autotest, test_ring); -- 2.7.4