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 267EDA052B; Fri, 31 Jul 2020 05:45:31 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D9E7F1BFFD; Fri, 31 Jul 2020 05:45:29 +0200 (CEST) Received: from mail-qk1-f196.google.com (mail-qk1-f196.google.com [209.85.222.196]) by dpdk.org (Postfix) with ESMTP id 7FD212862 for ; Fri, 31 Jul 2020 05:45:28 +0200 (CEST) Received: by mail-qk1-f196.google.com with SMTP id l64so20873966qkb.8 for ; Thu, 30 Jul 2020 20:45:28 -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; bh=tMVnCDU92oU4wMk+BXp+s/yl24+yJv4t5GmESyXY+OU=; b=GKba0YAF5iKNX51sECa2XyZKVsJXZoSD1CCCBquhTbh9KMb3b0BuG+A6Jz2ysVwYQp 5WdCOwROh6RPBE/mvz0o56X8VgGG5sVPcNahm8qtU46XeLgceG9Q6lvN20y4aGtuihKu PaEQDz/Qnxa+mSkTyhbBETsBBWlGfZrZrEleTT+TbSHfYKKLMWi+zT5HD+3lPK8uY2HK C0sujgLYlWLnBkrxKzMMAgNLhtpr4q9vuQfF9LMnHcgS32Rm63L0zI+8SzneJtBtG2mu /7m+yr10ipYPmzq53eKXW8VD5ugAWosOQ2N3LgRKAS+u3ytqbPF2ad2HhvHrConvu42Y itWQ== 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; bh=tMVnCDU92oU4wMk+BXp+s/yl24+yJv4t5GmESyXY+OU=; b=Xgj9tccxH3AK5Xyf7F0vQloVyFMUh/EMGZot/iJdXvcgwvwAfczuqv7k2qwHgeorPW 0u0lB3Ps3xS2oNGwp9EuJOzNvRABQbtAXV0wzV6cczkKQ9RFcl2ABJLKEXf9eRYCB/kr 8U+QfTZwd4IsHhCjyvN2kuevftvzxBhnJUAWx9bAHKKudfapaNFqItyDbN8GHYYDhdAZ 7nfUVkKz9plr1y5EW3NXuD3gyK117fQtw3xvTnITrajB+OeH2DpIyCbMJuiWSy71dxDQ 0AOTv2QJPjq643Tj9c0iegtDMy4b8OKpbB7J5Cb2z+YPud2iVs4VkZ/5TS0yqVn26cnv d5fw== X-Gm-Message-State: AOAM533gIh1cWRVpFqa4IPCnoLj0P/oQ5X9mIl2NFRhFKmaEw1m3sFqx zF8vqvlm9e+C/xfjnMk9L0I7kQ0omRg= X-Google-Smtp-Source: ABdhPJyX/P5u7+of9V9DAYzGo0VhczP2Rdi82I/m45XhOTTpEM+wC7XiKiqriZDKO/vSnas//dCDoA== X-Received: by 2002:a05:620a:15e9:: with SMTP id p9mr2357109qkm.38.1596167127684; Thu, 30 Jul 2020 20:45:27 -0700 (PDT) Received: from linux.home ([2604:2000:1344:41d:104e:9490:d5b7:450d]) by smtp.googlemail.com with ESMTPSA id t93sm7024563qtd.97.2020.07.30.20.45.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jul 2020 20:45:27 -0700 (PDT) From: Gaurav Singh To: dev@dpdk.org Cc: Gaurav Singh Date: Thu, 30 Jul 2020 23:45:20 -0400 Message-Id: <20200731034520.30791-1-gaurav1086@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-dev] [PATCH] librte_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 for sequential allocations. Signed-off-by: Gaurav Singh --- lib/librte_metrics/rte_metrics_telemetry.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/librte_metrics/rte_metrics_telemetry.c b/lib/librte_metrics/rte_metrics_telemetry.c index 289ebae0b..55c2b8478 100644 --- a/lib/librte_metrics/rte_metrics_telemetry.c +++ b/lib/librte_metrics/rte_metrics_telemetry.c @@ -167,9 +167,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