DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH v1] app/test-gpudev: remove memory leaks in case of errors
@ 2021-11-17 20:44 eagostini
  2021-11-17 16:33 ` David Marchand
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: eagostini @ 2021-11-17 20:44 UTC (permalink / raw)
  To: dev; +Cc: Elena Agostini

From: Elena Agostini <eagostini@nvidia.com>

Signed-off-by: Elena Agostini <eagostini@nvidia.com>
---
 app/test-gpudev/main.c | 41 ++++++++++++++++++++++++++++-------------
 1 file changed, 28 insertions(+), 13 deletions(-)

diff --git a/app/test-gpudev/main.c b/app/test-gpudev/main.c
index c647e30de4..fe5c1e5b15 100644
--- a/app/test-gpudev/main.c
+++ b/app/test-gpudev/main.c
@@ -70,7 +70,7 @@ alloc_gpu_memory(uint16_t gpu_id)
 	size_t buf_bytes = 1024;
 	int ret;
 
-	printf("\n=======> TEST: Allocate GPU memory\n\n");
+	printf("\nTEST: Allocate GPU memory\n\n");
 
 	/* Alloc memory on GPU 0 */
 	ptr_1 = rte_gpu_mem_alloc(gpu_id, buf_bytes);
@@ -113,11 +113,18 @@ alloc_gpu_memory(uint16_t gpu_id)
 	}
 	printf("GPU memory 0x%p freed\n", ptr_1);
 
-	printf("\n=======> TEST: PASSED\n");
+	printf("\nTEST: PASSED\n");
 	return 0;
 
 error:
-	printf("\n=======> TEST: FAILED\n");
+
+	if (ptr_1 != NULL)
+		rte_gpu_mem_free(gpu_id, ptr_1);
+
+	if (ptr_2 != NULL)
+		rte_gpu_mem_free(gpu_id, ptr_2);
+
+	printf("\nTEST: FAILED\n");
 	return -1;
 }
 
@@ -128,7 +135,7 @@ register_cpu_memory(uint16_t gpu_id)
 	size_t buf_bytes = 1024;
 	int ret;
 
-	printf("\n=======> TEST: Register CPU memory\n\n");
+	printf("\nTEST: Register CPU memory\n\n");
 
 	/* Alloc memory on CPU visible from GPU 0 */
 	ptr = rte_zmalloc(NULL, buf_bytes, 0);
@@ -161,11 +168,15 @@ register_cpu_memory(uint16_t gpu_id)
 	}
 	printf("CPU memory 0x%p unregistered\n", ptr);
 
-	printf("\n=======> TEST: PASSED\n");
+	printf("\nTEST: PASSED\n");
 	return 0;
 
 error:
-	printf("\n=======> TEST: FAILED\n");
+
+	if (ptr != NULL)
+		rte_gpu_mem_unregister(gpu_id, ptr);
+
+	printf("\nTEST: FAILED\n");
 	return -1;
 }
 
@@ -177,7 +188,7 @@ create_update_comm_flag(uint16_t gpu_id)
 	uint32_t set_val;
 	uint32_t get_val;
 
-	printf("\n=======> TEST: Communication flag\n\n");
+	printf("\nTEST: Communication flag\n\n");
 
 	ret = rte_gpu_comm_create_flag(gpu_id, &devflag, RTE_GPU_COMM_FLAG_CPU);
 	if (ret < 0) {
@@ -223,11 +234,13 @@ create_update_comm_flag(uint16_t gpu_id)
 		goto error;
 	}
 
-	printf("\n=======> TEST: PASSED\n");
+	printf("\nTEST: PASSED\n");
 	return 0;
 
 error:
-	printf("\n=======> TEST: FAILED\n");
+
+	rte_gpu_comm_destroy_flag(&devflag);
+	printf("\nTEST: FAILED\n");
 	return -1;
 }
 
@@ -254,11 +267,11 @@ create_update_comm_list(uint16_t gpu_id)
 {
 	int ret = 0;
 	int i = 0;
-	struct rte_gpu_comm_list *comm_list;
+	struct rte_gpu_comm_list *comm_list = NULL;
 	uint32_t num_comm_items = 1024;
 	struct rte_mbuf *mbufs[10];
 
-	printf("\n=======> TEST: Communication list\n\n");
+	printf("\nTEST: Communication list\n\n");
 
 	comm_list = rte_gpu_comm_create_list(gpu_id, num_comm_items);
 	if (comm_list == NULL) {
@@ -323,11 +336,13 @@ create_update_comm_list(uint16_t gpu_id)
 	for (i = 0; i < 10; i++)
 		rte_free(mbufs[i]);
 
-	printf("\n=======> TEST: PASSED\n");
+	printf("\nTEST: PASSED\n");
 	return 0;
 
 error:
-	printf("\n=======> TEST: FAILED\n");
+
+	rte_gpu_comm_destroy_list(comm_list, num_comm_items);
+	printf("\nTEST: FAILED\n");
 	return -1;
 }
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-11-26 12:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-17 20:44 [PATCH v1] app/test-gpudev: remove memory leaks in case of errors eagostini
2021-11-17 16:33 ` David Marchand
2021-11-18  1:23 ` [PATCH v2] " eagostini
2021-11-25 23:03 ` [PATCH v3] app/test-gpudev: remove all memory leaks eagostini
2021-11-26 12:17   ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).