From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id E9722A04B4; Sat, 8 Aug 2020 18:39:18 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D978D2C15; Sat, 8 Aug 2020 18:39:17 +0200 (CEST) Received: from mail-qk1-f195.google.com (mail-qk1-f195.google.com [209.85.222.195]) by dpdk.org (Postfix) with ESMTP id ED9A92B87 for ; Sat, 8 Aug 2020 18:39:16 +0200 (CEST) Received: by mail-qk1-f195.google.com with SMTP id 77so4571717qkm.5 for ; Sat, 08 Aug 2020 09:39:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XtfNPI2JBNM7ova2qlxtP2D9V2BmZxOIu2/7eAdUmQE=; b=thLjXFkLHnov64NojsOVFL9HxvkD5R0v0un0NPCd1Age4+unUhVGhgjUHLUOzMJFhf QQyZWLZxaVrEOZNGdFTGiOTLEZ6qtCHtnz3sLUYb0dRPBdUU4XozR+zofa+rkcwd0OYX g/T9+AX2xFTaeVjHrJbpeiQudSB0ub5o6y562iBBI80AubM64kPjLMXjLdX9NUiP0+NH iWjl14Erz+aUKnnTlpngVqUvbs+rIqUtGbr8QGKhtEJbvJSJWVCJFPZ9DxNjGMrDlJOg CztNQsVvjGnxbIb9t4U4SuvysEol7EOOKa5o87mNz/Vbr8454Gj+4tFTnTnsto0OiThf zzuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XtfNPI2JBNM7ova2qlxtP2D9V2BmZxOIu2/7eAdUmQE=; b=kKWZu6lyI9UeqAaWSEtXNjP+rgRQdGpMYer947ZV3ycEtVrU3iPPfI2dKvhQmSTk/W gcXzxdfyToTosrc+hB8w7yvai1XYzLmtc4v/eLrqlI6tfyfshUo1VYfFkNdt7t7Fy3Wk /OXMFofgDvWkUHNMfeiMlZOwdIRAMyZNVPNArZYIDHOv28qufIuQiZCehfgyUz2tjyDk TpnrTvm+Co07ppvADnOKQ3DYAroKryjCQiFUtyzQcE1/xEIFQg01PuLyTugPOuWvytp5 yDq6k3Knc1CJwB7EEZoqM5COBpjKk5ftdJ+TJP3E/TLINYI1LRrJJWMrJ8aw5RgWqaSN 6xuA== X-Gm-Message-State: AOAM530194SetV8jdVXpEws1QOsbwyhp4Bso93OhlpbKQ/IPP8g7gI6g lVbvYZRewkI8Mth5Sz8jSErI7gaY2wo= X-Google-Smtp-Source: ABdhPJyzleZctj9WvSg/bC9TQerbeQXfd7M2p/+2AO5rbpjVBmG3MSiqqJ3w3ivWACucZ0g9ckNPvQ== X-Received: by 2002:a37:582:: with SMTP id 124mr18644563qkf.400.1596904756213; Sat, 08 Aug 2020 09:39:16 -0700 (PDT) Received: from linux.home ([2604:2000:1344:41d:d81:1efe:2043:bb12]) by smtp.googlemail.com with ESMTPSA id b187sm5821183qkd.107.2020.08.08.09.39.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Aug 2020 09:39:15 -0700 (PDT) From: Gaurav Singh To: dev@dpdk.org Cc: Gaurav Singh Date: Sat, 8 Aug 2020 12:39:06 -0400 Message-Id: <20200808163906.8021-1-gaurav1086@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200731034520.30791-1-gaurav1086@gmail.com> References: <20200731034520.30791-1-gaurav1086@gmail.com> Subject: [dpdk-dev] [PATCH] lib/metrics: fix memory leak X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 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" fix memory leak Fixes: c5b7197f66 ("telemetry: move some functions to metrics library") Signed-off-by: Gaurav Singh --- lib/librte_metrics/rte_metrics_telemetry.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/librte_metrics/rte_metrics_telemetry.c b/lib/librte_metrics/rte_metrics_telemetry.c index 289ebae0b..7b6d1063c 100644 --- a/lib/librte_metrics/rte_metrics_telemetry.c +++ b/lib/librte_metrics/rte_metrics_telemetry.c @@ -41,12 +41,17 @@ rte_metrics_tel_reg_port_ethdev_to_metrics(uint16_t port_id) } xstats_names = malloc(sizeof(*xstats_names) * num_xstats); + if (xstats_names == NULL) { + METRICS_LOG_ERR("Failed to malloc memory for xstats_names"); + return -ENOMEM; + } + eth_xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * num_xstats); - if (eth_xstats_names == NULL || xstats_names == NULL) { - METRICS_LOG_ERR("Failed to malloc memory for xstats_names"); - ret = -ENOMEM; - goto free_xstats; + if (eth_xstats_names == NULL) { + METRICS_LOG_ERR("Failed to malloc memory for eth_xstats_names"); + free(xstats_names); + return -ENOMEM; } if (rte_eth_xstats_get_names(port_id, @@ -167,9 +172,15 @@ rte_metrics_tel_format_port(uint32_t pid, json_t *ports, } metrics = malloc(sizeof(struct rte_metric_value) * num_metrics); + if (metrics == NULL) { + METRICS_LOG_ERR("Cannot allocate memory"); + return -ENOMEM; + } + names = malloc(sizeof(struct rte_metric_name) * num_metrics); - if (metrics == NULL || names == NULL) { + if (names == NULL) { METRICS_LOG_ERR("Cannot allocate memory"); + free(metrics); return -ENOMEM; } -- 2.17.1