From nobody Mon Apr 6 20:11:41 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16DE9ECAAD4 for ; Sat, 3 Sep 2022 06:51:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232654AbiICGvE (ORCPT ); Sat, 3 Sep 2022 02:51:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231938AbiICGu6 (ORCPT ); Sat, 3 Sep 2022 02:50:58 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E0287E33A; Fri, 2 Sep 2022 23:50:57 -0700 (PDT) Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4MKQNw4x5CzrS34; Sat, 3 Sep 2022 14:49:04 +0800 (CST) Received: from kwepemm600008.china.huawei.com (7.193.23.88) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 3 Sep 2022 14:50:54 +0800 Received: from huawei.com (10.175.100.227) by kwepemm600008.china.huawei.com (7.193.23.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 3 Sep 2022 14:50:53 +0800 From: Shang XiaoJing To: , , , , , , , , CC: Subject: [PATCH 3/3] perf c2c: Prevent potential memory leak in c2c_he_zalloc Date: Sat, 3 Sep 2022 15:25:42 +0800 Message-ID: <20220903072542.27678-4-shangxiaojing@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220903072542.27678-1-shangxiaojing@huawei.com> References: <20220903072542.27678-1-shangxiaojing@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.100.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600008.china.huawei.com (7.193.23.88) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Free allocated resources when zalloc is failed for members in c2c_he, to prevent potential memory leak in c2c_he_zalloc. Signed-off-by: Shang XiaoJing Acked-by: Jiri Olsa --- tools/perf/builtin-c2c.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index 12f272811487..5530433eda80 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -146,15 +146,15 @@ static void *c2c_he_zalloc(size_t size) =20 c2c_he->cpuset =3D bitmap_zalloc(c2c.cpus_cnt); if (!c2c_he->cpuset) - return NULL; + goto out_free_he; =20 c2c_he->nodeset =3D bitmap_zalloc(c2c.nodes_cnt); if (!c2c_he->nodeset) - return NULL; + goto out_free_cpuset; =20 c2c_he->node_stats =3D zalloc(c2c.nodes_cnt * sizeof(*c2c_he->node_stats)= ); if (!c2c_he->node_stats) - return NULL; + goto out_free_nodeset; =20 init_stats(&c2c_he->cstats.lcl_hitm); init_stats(&c2c_he->cstats.rmt_hitm); @@ -163,6 +163,14 @@ static void *c2c_he_zalloc(size_t size) init_stats(&c2c_he->cstats.load); =20 return &c2c_he->he; + +out_free_nodeset: + free(c2c_he->nodeset); +out_free_cpuset: + free(c2c_he->cpuset); +out_free_he: + free(c2c_he); + return NULL; } =20 static void c2c_he_free(void *he) --=20 2.17.1