DPDK patches and discussions
 help / color / mirror / Atom feed
From: <eagostini@nvidia.com>
To: <dev@dpdk.org>
Cc: Elena Agostini <eagostini@nvidia.com>
Subject: [PATCH v3] app/test-gpudev: remove all memory leaks
Date: Thu, 25 Nov 2021 23:03:32 +0000	[thread overview]
Message-ID: <20211125230332.15709-1-eagostini@nvidia.com> (raw)
In-Reply-To: <20211117204453.27337-1-eagostini@nvidia.com>

From: Elena Agostini <eagostini@nvidia.com>

Remove all memory leaks in case of errors in
test-gpudev application.

Fixes: e818c4e2bf50 ("gpudev: add memory API")
Fixes: c7ebd65c1372 ("gpudev: add communication list")

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

diff --git a/app/test-gpudev/main.c b/app/test-gpudev/main.c
index c647e30de4..5c1aa3d52f 100644
--- a/app/test-gpudev/main.c
+++ b/app/test-gpudev/main.c
@@ -117,6 +117,10 @@ alloc_gpu_memory(uint16_t gpu_id)
 	return 0;
 
 error:
+
+	rte_gpu_mem_free(gpu_id, ptr_1);
+	rte_gpu_mem_free(gpu_id, ptr_2);
+
 	printf("\n=======> TEST: FAILED\n");
 	return -1;
 }
@@ -161,10 +165,15 @@ register_cpu_memory(uint16_t gpu_id)
 	}
 	printf("CPU memory 0x%p unregistered\n", ptr);
 
+	rte_free(ptr);
+
 	printf("\n=======> TEST: PASSED\n");
 	return 0;
 
 error:
+
+	rte_gpu_mem_unregister(gpu_id, ptr);
+	rte_free(ptr);
 	printf("\n=======> TEST: FAILED\n");
 	return -1;
 }
@@ -227,6 +236,8 @@ create_update_comm_flag(uint16_t gpu_id)
 	return 0;
 
 error:
+
+	rte_gpu_comm_destroy_flag(&devflag);
 	printf("\n=======> TEST: FAILED\n");
 	return -1;
 }
@@ -254,7 +265,7 @@ 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];
 
@@ -327,6 +338,10 @@ create_update_comm_list(uint16_t gpu_id)
 	return 0;
 
 error:
+
+	rte_gpu_comm_destroy_list(comm_list, num_comm_items);
+	for (i = 0; i < 10; i++)
+		rte_free(mbufs[i]);
 	printf("\n=======> TEST: FAILED\n");
 	return -1;
 }
-- 
2.17.1


  parent reply	other threads:[~2021-11-25 14:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` eagostini [this message]
2021-11-26 12:17   ` [PATCH v3] app/test-gpudev: remove all memory leaks Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211125230332.15709-1-eagostini@nvidia.com \
    --to=eagostini@nvidia.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).