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 D6EEEA053E; Sat, 1 Aug 2020 03:46:44 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 2EB7A2629; Sat, 1 Aug 2020 03:46:44 +0200 (CEST) Received: from mail-qv1-f67.google.com (mail-qv1-f67.google.com [209.85.219.67]) by dpdk.org (Postfix) with ESMTP id 133D911A2 for ; Sat, 1 Aug 2020 03:46:43 +0200 (CEST) Received: by mail-qv1-f67.google.com with SMTP id dd12so9995341qvb.0 for ; Fri, 31 Jul 2020 18:46:42 -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=ovbNNNarVE1fSaXE0nc+/J76y6MxGsjGBWc7fX1CzWQ=; b=PsHtl+V6JNSkaASa33eY7dBXmi4V6zux4KQq11Z3QllQYrhqzc4Pp6kwgS+M4fLHql GNpOR9mM9OhjjLbvEhtsPkFcRMJHkzXE9f5H5c7Vmv0DjKNd5T9+73fUMZp8uOvYKR5h fOhJ+3BrPb42giHFVzOVH8+yadg3U55isFv4x1Fso5Wii7RZJkzeUouuT5UXfyKiGgJq oY8+6TctkW8y2b1Wh+XorOcLnwkwpouyQkSV0FdEy20wqfxCVtMOtE6dKm7gidK05ZSr 0pGQP+mHkypDrmh36Nd6/CBWCHG2BFQcogcsj83wlOa+tHCIRcH2HhQQ3nHcQ2LOf7hg luOg== 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=ovbNNNarVE1fSaXE0nc+/J76y6MxGsjGBWc7fX1CzWQ=; b=VMwKEy7WDL7scXuBphrINrqszW4i1BIqInA0fLCTCPHvJAxUPepwEOXheduJrEF/1R JlbGpzYhVYzUWwoNjC7znfl0QiCSasqDEzBsfR20U/YL6FbnuqkmVrRboCowDuDh5zzT pwx8zkRzz4DU8hanacSs8y2kmE/X7fq9OGYICN3ZT7dbba7TXe59wZf9UhPnMOlQmXkd XdFvI9/PJ9q7AbzDQsrUwxCxqX3wTmmsph37nOxWy+sXSMltq7B9HwcszY5gbhdtaz3C D8SCDXMZYvJilF4HHWzeYnQmY+wnZ68tikaSxqLzQGzXS5BYi4b+ksZm70Om5Ng1aFWt P3Qg== X-Gm-Message-State: AOAM533HtyfSk1HUMtDQSgrfdSykReKzolCqo0qy6DtUJMtEke3aXzJM xbhMf6wgx7sOWog4MVzoBfqLHDWsQCU= X-Google-Smtp-Source: ABdhPJwRFhrkfBtM/J+bff05V8lDQtXmomcOl/HgW3TOGH1dMpaDNNMXCBmZfiDrVp3mSq6MRmxiGA== X-Received: by 2002:a05:6214:1302:: with SMTP id a2mr6950099qvv.156.1596246402201; Fri, 31 Jul 2020 18:46:42 -0700 (PDT) Received: from linux.home ([2604:2000:1344:41d:104e:9490:d5b7:450d]) by smtp.googlemail.com with ESMTPSA id z3sm10899352qkc.4.2020.07.31.18.46.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2020 18:46:41 -0700 (PDT) From: Gaurav Singh To: dev@dpdk.org Cc: Gaurav Singh Date: Fri, 31 Jul 2020 21:46:27 -0400 Message-Id: <20200801014627.15127-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] 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 | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/librte_metrics/rte_metrics_telemetry.c b/lib/librte_metrics/rte_metrics_telemetry.c index 289ebae0b..e12c69fe0 100644 --- a/lib/librte_metrics/rte_metrics_telemetry.c +++ b/lib/librte_metrics/rte_metrics_telemetry.c @@ -41,11 +41,18 @@ 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"); + ret = -ENOMEM; + goto free_xstats; + } + eth_xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * num_xstats); - if (eth_xstats_names == NULL || xstats_names == NULL) { + if (eth_xstats_names == NULL) { METRICS_LOG_ERR("Failed to malloc memory for xstats_names"); ret = -ENOMEM; + free(xstats_names); goto free_xstats; } @@ -167,9 +174,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