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 EFDDFA0524; Tue, 13 Apr 2021 05:15:00 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E08BD1609C3; Tue, 13 Apr 2021 05:15:00 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by mails.dpdk.org (Postfix) with ESMTP id 0C5571609BF for ; Tue, 13 Apr 2021 05:14:59 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE1 (envelope-from xuemingl@nvidia.com) with SMTP; 13 Apr 2021 06:14:55 +0300 Received: from nvidia.com (pegasus05.mtr.labs.mlnx [10.210.16.100]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 13D3EQxq015492; Tue, 13 Apr 2021 06:14:55 +0300 From: Xueming Li To: Thomas Monjalon , Gaetan Rivet Cc: dev@dpdk.org, xuemingl@nvidia.com, Asaf Penso , gaetan.rivet@6wind.com, stable@dpdk.org, Shreyansh Jain Date: Tue, 13 Apr 2021 03:14:09 +0000 Message-Id: <1618283653-16510-3-git-send-email-xuemingl@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1618283653-16510-1-git-send-email-xuemingl@nvidia.com> References: <1618283653-16510-1-git-send-email-xuemingl@nvidia.com> In-Reply-To: <1608304614-13908-2-git-send-email-xuemingl@nvidia.com> References: <1608304614-13908-2-git-send-email-xuemingl@nvidia.com> Subject: [dpdk-dev] [PATCH v5 2/5] devargs: fix memory leak on parsing error 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 Sender: "dev" This patch fixes memory leak in parsing error handling. Fixes: 338327d731e6 ("devargs: add function to parse device layers") Cc: gaetan.rivet@6wind.com Cc: stable@dpdk.org Signed-off-by: Xueming Li Reviewed-by: Gaetan Rivet --- lib/librte_eal/common/eal_common_devargs.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c index 48f85ee9c0..e40b91ea66 100644 --- a/lib/librte_eal/common/eal_common_devargs.c +++ b/lib/librte_eal/common/eal_common_devargs.c @@ -60,6 +60,7 @@ rte_devargs_layers_parse(struct rte_devargs *devargs, size_t nblayer; size_t i = 0; int ret = 0; + bool allocated_data = false; /* Split each sub-lists. */ nblayer = devargs_layer_count(devstr); @@ -81,6 +82,7 @@ rte_devargs_layers_parse(struct rte_devargs *devargs, ret = -ENOMEM; goto get_out; } + allocated_data = true; s = devargs->data; } @@ -163,8 +165,14 @@ rte_devargs_layers_parse(struct rte_devargs *devargs, if (layers[i].kvlist) rte_kvargs_free(layers[i].kvlist); } - if (ret != 0) + if (ret != 0) { + if (allocated_data) { + /* Free duplicated data. */ + free(devargs->data); + devargs->data = NULL; + } rte_errno = -ret; + } return ret; } -- 2.25.1