From patchwork Thu May 6 07:16:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "humin (Q)" X-Patchwork-Id: 92988 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 92EE8A0524; Thu, 6 May 2021 09:16:37 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 09860410F9; Thu, 6 May 2021 09:16:32 +0200 (CEST) Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) by mails.dpdk.org (Postfix) with ESMTP id 1F7E3410F3 for ; Thu, 6 May 2021 09:16:29 +0200 (CEST) Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4FbPvw1P64zklS4; Thu, 6 May 2021 15:14:20 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.498.0; Thu, 6 May 2021 15:16:24 +0800 From: "Min Hu (Connor)" To: CC: , , , , Date: Thu, 6 May 2021 15:16:26 +0800 Message-ID: <1620285387-42792-2-git-send-email-humin29@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1620285387-42792-1-git-send-email-humin29@huawei.com> References: <1619092340-4047-1-git-send-email-humin29@huawei.com> <1620285387-42792-1-git-send-email-humin29@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH v2 1/2] graph: fix memory leak X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" From: HongBo Zheng Fix function 'stats_mem_populate' return without free dynamic memory referenced by 'stats'. Fixes: af1ae8b6a32c ("graph: implement stats") Cc: stable@dpdk.org Signed-off-by: HongBo Zheng Signed-off-by: Min Hu (Connor) Reviewed-by: David Marchand --- lib/graph/graph_stats.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/graph/graph_stats.c b/lib/graph/graph_stats.c index 125e08d..30e295d 100644 --- a/lib/graph/graph_stats.c +++ b/lib/graph/graph_stats.c @@ -165,6 +165,7 @@ stats_mem_populate(struct rte_graph_cluster_stats **stats_in, stats = realloc(stats, stats->sz + stats->cluster_node_size); if (stats == NULL) SET_ERR_JMP(ENOMEM, err, "Realloc failed"); + *stats_in = NULL; /* Clear the new struct cluster_node area */ cluster = RTE_PTR_ADD(stats, stats->sz), @@ -174,7 +175,7 @@ stats_mem_populate(struct rte_graph_cluster_stats **stats_in, cluster->stat.hz = rte_get_timer_hz(); node = graph_node_id_to_ptr(graph, id); if (node == NULL) - SET_ERR_JMP(ENOENT, err, "Failed to find node %s in graph %s", + SET_ERR_JMP(ENOENT, free, "Failed to find node %s in graph %s", graph_node->node->name, graph->name); cluster->nodes[cluster->nb_nodes++] = node; @@ -183,6 +184,8 @@ stats_mem_populate(struct rte_graph_cluster_stats **stats_in, *stats_in = stats; return 0; +free: + free(stats); err: return -rte_errno; } From patchwork Thu May 6 07:16:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "humin (Q)" X-Patchwork-Id: 92987 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 75A4CA0524; Thu, 6 May 2021 09:16:31 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E2EAE410F3; Thu, 6 May 2021 09:16:30 +0200 (CEST) Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) by mails.dpdk.org (Postfix) with ESMTP id 1A9B8410F2 for ; Thu, 6 May 2021 09:16:29 +0200 (CEST) Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4FbPvw1gLhzklS6; Thu, 6 May 2021 15:14:20 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.498.0; Thu, 6 May 2021 15:16:25 +0800 From: "Min Hu (Connor)" To: CC: , , , , Date: Thu, 6 May 2021 15:16:27 +0800 Message-ID: <1620285387-42792-3-git-send-email-humin29@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1620285387-42792-1-git-send-email-humin29@huawei.com> References: <1619092340-4047-1-git-send-email-humin29@huawei.com> <1620285387-42792-1-git-send-email-humin29@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH v2 2/2] graph: fix dereferencing null pointer X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" From: HongBo Zheng In function 'stats_mem_init', pointer 'stats' should be confirmed not null before memset it. Fixes: af1ae8b6a32c ("graph: implement stats") Cc: stable@dpdk.org Signed-off-by: HongBo Zheng Signed-off-by: Min Hu (Connor) Reviewed-by: Jerin Jacob Reviewed-by: David Marchand --- lib/graph/graph_stats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/graph/graph_stats.c b/lib/graph/graph_stats.c index 30e295d..aa70929 100644 --- a/lib/graph/graph_stats.c +++ b/lib/graph/graph_stats.c @@ -119,8 +119,8 @@ stats_mem_init(struct cluster *cluster, cluster_node_size = RTE_ALIGN(cluster_node_size, RTE_CACHE_LINE_SIZE); stats = realloc(NULL, sz); - memset(stats, 0, sz); if (stats) { + memset(stats, 0, sz); stats->fn = fn; stats->cluster_node_size = cluster_node_size; stats->max_nodes = 0;