[dpdk-dev] [PATCH] test_distributor.c: prevent memory leakages from the pool

Sarosh Arif sarosh.arif at emumba.com
Mon Apr 13 11:19:06 CEST 2020


rte_mempool_get_bulk is used to get bufs/many_bufs from the pool,
but at some locations when test passes/fails the bufs/many_bufs are
not returned back to the pool.
Due to this, multiple executions of distributor_autotest gives the
following error message: Error getting mbufs from pool.
To resolve this issue rte_mempool_put_bulk is used whenever the test
passes/fails and returns.   

Signed-off-by: Sarosh Arif <sarosh.arif at emumba.com>
---
 app/test/test_distributor.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/app/test/test_distributor.c b/app/test/test_distributor.c
index ba1f81cf8..8608b4ce8 100644
--- a/app/test/test_distributor.c
+++ b/app/test/test_distributor.c
@@ -128,6 +128,7 @@ sanity_test(struct worker_params *wp, struct rte_mempool *p)
 		printf("Line %d: Error, not all packets flushed. "
 				"Expected %u, got %u\n",
 				__LINE__, BURST, total_packet_count());
+		rte_mempool_put_bulk(p, (void *)bufs, BURST);
 		return -1;
 	}
 
@@ -153,6 +154,7 @@ sanity_test(struct worker_params *wp, struct rte_mempool *p)
 			printf("Line %d: Error, not all packets flushed. "
 					"Expected %u, got %u\n",
 					__LINE__, BURST, total_packet_count());
+			rte_mempool_put_bulk(p, (void *)bufs, BURST);
 			return -1;
 		}
 
@@ -179,6 +181,7 @@ sanity_test(struct worker_params *wp, struct rte_mempool *p)
 		printf("Line %d: Error, not all packets flushed. "
 				"Expected %u, got %u\n",
 				__LINE__, BURST, total_packet_count());
+		rte_mempool_put_bulk(p, (void *)bufs, BURST);
 		return -1;
 	}
 
@@ -233,6 +236,7 @@ sanity_test(struct worker_params *wp, struct rte_mempool *p)
 	if (num_returned != BIG_BATCH) {
 		printf("line %d: Missing packets, expected %d\n",
 				__LINE__, num_returned);
+		rte_mempool_put_bulk(p, (void *)many_bufs, BIG_BATCH);
 		return -1;
 	}
 
@@ -247,6 +251,7 @@ sanity_test(struct worker_params *wp, struct rte_mempool *p)
 
 		if (j == BIG_BATCH) {
 			printf("Error: could not find source packet #%u\n", i);
+			rte_mempool_put_bulk(p, (void *)many_bufs, BIG_BATCH);
 			return -1;
 		}
 	}
@@ -327,10 +332,12 @@ sanity_test_with_mbuf_alloc(struct worker_params *wp, struct rte_mempool *p)
 		printf("Line %u: Packet count is incorrect, %u, expected %u\n",
 				__LINE__, total_packet_count(),
 				(1<<ITER_POWER));
+		rte_mempool_put_bulk(p, (void *)bufs, BURST);
 		return -1;
 	}
 
 	printf("Sanity test with mbuf alloc/free passed\n\n");
+	rte_mempool_put_bulk(p, (void *)bufs, BURST);
 	return 0;
 }
 
@@ -450,10 +457,14 @@ sanity_test_with_worker_shutdown(struct worker_params *wp,
 		printf("Line %d: Error, not all packets flushed. "
 				"Expected %u, got %u\n",
 				__LINE__, BURST * 2, total_packet_count());
+		for (i = 0; i < 2; i++)
+			rte_mempool_put_bulk(p, (void *)bufs, BURST);
 		return -1;
 	}
 
 	printf("Sanity test with worker shutdown passed\n\n");
+	for (i = 0; i < 2; i++)
+		rte_mempool_put_bulk(p, (void *)bufs, BURST);
 	return 0;
 }
 
@@ -503,10 +514,12 @@ test_flush_with_worker_shutdown(struct worker_params *wp,
 		printf("Line %d: Error, not all packets flushed. "
 				"Expected %u, got %u\n",
 				__LINE__, BURST, total_packet_count());
+		rte_mempool_put_bulk(p, (void *)bufs, BURST);
 		return -1;
 	}
 
 	printf("Flush test with worker shutdown passed\n\n");
+	rte_mempool_put_bulk(p, (void *)bufs, BURST);
 	return 0;
 }
 
-- 
2.17.1


More information about the dev mailing list