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 8391EA053E; Sat, 1 Aug 2020 08:08:48 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B1A102629; Sat, 1 Aug 2020 08:08:47 +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 0A9CB11A2 for ; Sat, 1 Aug 2020 08:08:46 +0200 (CEST) Received: by mail-qv1-f67.google.com with SMTP id dd12so10131690qvb.0 for ; Fri, 31 Jul 2020 23:08:46 -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=tir1TBPx5SfKCYZuw9AOVxolkaxiunDsp8vqenZf3r0=; b=HlnjXxWjQ6VonC596TlKr20z288IVhDZg2I2H5+EIgXkWnYiEuJPEWz6ycZFsCJq4b ChHbrdlM8YdcCQ20G4EgqYZNk9ITnHLaU72gMf08q21QVnQMXyVGWyVmxwT46qCHgYZr uES1Haf7W1aKhGENR0BkRbnJPJDFh9ycWQQBAG0wr5bZLhoYkiOvrocOKFCb808U49Rk SCdZpRbvfREYUjf+s2KZV58WSkEpgcS7FdWFWIFzPMMqSmxgfXnfmwlO4z1ba2uyw5tx 5iDu2nT4FypzSheZopNj/XGmI9DgPGOtDWMbaAXVVkrOqWyvh3fCsJrSmyRsK+9XBh2+ f8dA== 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=tir1TBPx5SfKCYZuw9AOVxolkaxiunDsp8vqenZf3r0=; b=PizEbp7cKDf7M8ZRDF6/2bLt3QIG5ZmLxZHyb4V8A5CZbWtt20neRe8VJoFVVALNmd PonEABaUgbJ/JDBOgQD8rMVuTVWr6231xq+XwSnjpEkrRMbOgYIUBUTStFFtZ8+6zIUS JE+M8NaMXVaWIzue1UaIAT7TgyXeW6rLNhD5facnN8b/1Wh+b5isVevbr/x5T8u0OAF/ xtEjqdWIQJwrm/c9ojCZXwZcEG5ECD9H38l6oKfXdRE9BNhehs+Zo1cLtnF6WZMllA3A iqb6H0CNaNL0R/+Uch3M4p/zQeYqCJSTd/R0rbyO68vUgdrec6XCubiJT0MsiDjQx+c4 PdIQ== X-Gm-Message-State: AOAM533HzC9P5oardUtof2lZSiY7v2qZp/TCH7/Gkdz9OwM2QzkBsLwE 8r3Euqvpt3BZbs6VT+C9ho0Q/+tw/MA= X-Google-Smtp-Source: ABdhPJxFkNKoTPnw7U8WTbVnbaYGjRscKi24jzO15LBeOUDpZgMSdt8QC/xQtYLfi8yVpEWywqHCfg== X-Received: by 2002:a05:6214:554:: with SMTP id ci20mr7487965qvb.108.1596262126195; Fri, 31 Jul 2020 23:08:46 -0700 (PDT) Received: from linux.home ([2604:2000:1344:41d:9d7e:9294:e3f7:a719]) by smtp.googlemail.com with ESMTPSA id x198sm12833761qka.37.2020.07.31.23.08.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2020 23:08:45 -0700 (PDT) From: Gaurav Singh To: dev@dpdk.org Cc: Gaurav Singh Date: Sat, 1 Aug 2020 02:08:38 -0400 Message-Id: <20200801060838.20591-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 issue Signed-off-by: Gaurav Singh --- lib/librte_metrics/rte_metrics_telemetry.c | 24 +++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/librte_metrics/rte_metrics_telemetry.c b/lib/librte_metrics/rte_metrics_telemetry.c index 289ebae0b..9fbe59c62 100644 --- a/lib/librte_metrics/rte_metrics_telemetry.c +++ b/lib/librte_metrics/rte_metrics_telemetry.c @@ -41,12 +41,19 @@ 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; + return ret; + } + 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; - goto free_xstats; + free(xstats_names); + return ret; } if (rte_eth_xstats_get_names(port_id, @@ -54,7 +61,7 @@ rte_metrics_tel_reg_port_ethdev_to_metrics(uint16_t port_id) METRICS_LOG_ERR("rte_eth_xstats_get_names(%u) len %d failed", port_id, num_xstats); ret = -EPERM; - goto free_xstats; + return ret; } for (i = 0; i < num_xstats; i++) @@ -63,9 +70,6 @@ rte_metrics_tel_reg_port_ethdev_to_metrics(uint16_t port_id) if (ret < 0) METRICS_LOG_ERR("rte_metrics_reg_names failed - metrics may already be registered"); -free_xstats: - free(eth_xstats_names); - free(xstats_names); return ret; } @@ -167,9 +171,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