From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A60FFA0C41; Wed, 17 Nov 2021 17:34:11 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7202C40687; Wed, 17 Nov 2021 17:34:11 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mails.dpdk.org (Postfix) with ESMTP id 7489540040 for ; Wed, 17 Nov 2021 17:34:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637166849; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gz+ZHePIvGz10N/Klfsx7QVOH9tJXHvEhCA4n4YIaVE=; b=KZqO/fHUpbef+3/mWBnoF/VIrY4RwNmXeFU1P9ze90KuUspThrOpeOf6gk2lZVYndZPszJ MTxLj3obOINJWgWNVhHBlSFPzab0/tsDge/g6vzGC/6UVfp1LKTZBcWuqqkWmHZTPXp7jt Owvp/KueIADeibhBl9QgpX4tMkY3KRs= Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-537-_pjY7oEsPi68Yxre4qz-Iw-1; Wed, 17 Nov 2021 11:34:08 -0500 X-MC-Unique: _pjY7oEsPi68Yxre4qz-Iw-1 Received: by mail-lf1-f70.google.com with SMTP id z1-20020a056512308100b003ff78e6402bso1897143lfd.4 for ; Wed, 17 Nov 2021 08:34:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=gz+ZHePIvGz10N/Klfsx7QVOH9tJXHvEhCA4n4YIaVE=; b=sOCp8qi+wStPsp1thutf1hmbA4KOehWcqckYZC/DU8U/LqZuORBme5FfrAtN4U3Blj gc5nKKzHGH3x8N9WEGtO2NuxeheuKmtrpBp0GK33i2gr5sn0iM25g8TQ+DWdFe0m9Zeh 3gNVSgu2Ee8yRDWUp+pXLJgTHkup0g3Dpgga1naFrEbPGCA9lBlbIlv7oadr8RxuEl2R /I3NWp+Zcbn4z8SFaBPOJnGK/abCfoIRp3PoZssZh2q2z05s6XeOsXxGdcUkwGX/bU9S DlBnyTjKpPYuwK4Y15bQeuSXBIhEuIefAGmXQZm64SEvg7T+ywrl/GvB7tRDIaKIdyNr HRcw== X-Gm-Message-State: AOAM530wWJjmmiPaEJYpNvD1A9HLSYjh5dHXlJM3a+zGQrXNNee5lPTx sYESIbGaQ6kiDymZ++A+9LQGBC2q2T/nlM5lqrKAt7mhMSZrzu6R2PMxwCC0+KYzqiTyCfAyiTK bNuZ37piOUkODuT0LgN4= X-Received: by 2002:a2e:96c2:: with SMTP id d2mr9251355ljj.46.1637166846899; Wed, 17 Nov 2021 08:34:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJyO26hdBMtGAXfJFToWGK/KMg7OtHZ7m52eYB6WYdVbVd8yz9eFmxehHxKPEPsp0cnrxDw1ef43ZbK3A1TOprA= X-Received: by 2002:a2e:96c2:: with SMTP id d2mr9251320ljj.46.1637166846623; Wed, 17 Nov 2021 08:34:06 -0800 (PST) MIME-Version: 1.0 References: <20211117204453.27337-1-eagostini@nvidia.com> In-Reply-To: <20211117204453.27337-1-eagostini@nvidia.com> From: David Marchand Date: Wed, 17 Nov 2021 17:33:55 +0100 Message-ID: Subject: Re: [PATCH v1] app/test-gpudev: remove memory leaks in case of errors To: Elena Agostini Cc: dev , Thomas Monjalon Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dmarchan@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Wed, Nov 17, 2021 at 1:34 PM wrote: Commitlog. + Fixes: tag. > > From: Elena Agostini > > Signed-off-by: Elena Agostini > --- > 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"); This hunk (and others removing =====>) is not related to fixing leaks. Please drop. > > /* 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); rte_gpu_mem_free() should handle NULL pointer. Maybe something to change in lib/gpudev itself. > + > + 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); I'd expect a rte_free(ptr); here. > + > + 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); What about "mbufs" objects? > + printf("\nTEST: FAILED\n"); > return -1; > } > > -- > 2.17.1 > -- David Marchand