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 DDEA5A04C1 for ; Thu, 17 Sep 2020 17:06:30 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id BB2A01C19F; Thu, 17 Sep 2020 17:06:30 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 3C0BC160; Thu, 17 Sep 2020 17:06:25 +0200 (CEST) IronPort-SDR: T1jVvQsuMH4eDqTPZI5Dobb9qF8OJ6ZOCfi5ZvMffrv6xm06LLrWm1UBHMJTMW07vSmBvWLOLh pjQlySY7QPaw== X-IronPort-AV: E=McAfee;i="6000,8403,9747"; a="177811565" X-IronPort-AV: E=Sophos;i="5.77,437,1596524400"; d="scan'208";a="177811565" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Sep 2020 08:06:08 -0700 IronPort-SDR: 4ZyMTAgAzP7qRHUiyk0s5ysUV9tCDC3Uwmae8NLVyYfzk86xzMJ1DWPv7ckoxinEthjOZF1G7+ Og5kDV0C8dxQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,271,1596524400"; d="scan'208";a="508472049" Received: from silpixa00399953.ir.intel.com (HELO silpixa00399953.ger.corp.intel.com) ([10.237.222.53]) by fmsmga005.fm.intel.com with ESMTP; 17 Sep 2020 08:05:51 -0700 From: Ciara Power To: dev@dpdk.org Cc: Ciara Power , stable@dpdk.org, Keith Wiles Date: Thu, 17 Sep 2020 16:03:41 +0100 Message-Id: <20200917150341.66298-1-ciara.power@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-stable] [PATCH] metrics: fix resource leak on memory allocation fail X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" If an error occurred when allocating memory for metrics or names, the function returned without freeing allocated memory. This is now fixed to avoid the resource leak in the case that either metrics or names had been successfully allocated memory. Coverity issue: 362053 Fixes: c5b7197f662e ("telemetry: move some functions to metrics library") Cc: stable@dpdk.org Signed-off-by: Ciara Power --- lib/librte_metrics/rte_metrics_telemetry.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/librte_metrics/rte_metrics_telemetry.c b/lib/librte_metrics/rte_metrics_telemetry.c index 289ebae0bd..36a3821b4c 100644 --- a/lib/librte_metrics/rte_metrics_telemetry.c +++ b/lib/librte_metrics/rte_metrics_telemetry.c @@ -170,7 +170,8 @@ rte_metrics_tel_format_port(uint32_t pid, json_t *ports, names = malloc(sizeof(struct rte_metric_name) * num_metrics); if (metrics == NULL || names == NULL) { METRICS_LOG_ERR("Cannot allocate memory"); - return -ENOMEM; + ret = -ENOMEM; + goto fail; } if (rte_metrics_get_names(names, num_metrics) != num_metrics || -- 2.17.1