Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp683554rwb; Sat, 3 Sep 2022 00:11:58 -0700 (PDT) X-Google-Smtp-Source: AA6agR4wIUajQP+FxJyhwk7iJn6CP4x4+iyqVMCC5CJW9ux3qf7bZF8zIgPo6g9fZoEjyc6aU5HU X-Received: by 2002:a17:90b:4a48:b0:1fd:df0a:eac1 with SMTP id lb8-20020a17090b4a4800b001fddf0aeac1mr9013378pjb.161.1662189118242; Sat, 03 Sep 2022 00:11:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662189118; cv=none; d=google.com; s=arc-20160816; b=lmcpM30vT+6Fpcrr/jqLa4yFwXmayXmVrVOZBiaeN89HnFThaDwo59Giz2hKmVor3/ fBOs5poRbT9J+eJtAAAOH3RjRN7h4F4jcWbfl1XmkIbuNHXM10rrBvMf4d7RtDn302JD Hz54vgOptOjfhO9f9QVIsnbkh7x2iIFXV+IlnJMZPl08lnmJ17w+9P91n8z8EqP8m2u4 5lKmc5pg1msmwPQhSaCpmuG/0WMybXMgSujEpg9DGDmJK7kv0WPc+oaytbB2bWxCZkdR yUHLMXA7xlrdmqbnX2Tzc82A54q8MN/nid4U3qZUkKJRt0c4rp+y4F7uXxGrl3ZhsaKp 40LQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=AcV2tQNgGBVRTqeS5iXQ6ZfmB90OgglWgowiDAC4qAE=; b=gj4y1us31XBtpe6eQRqBzClSoNhJcNn+ipC60xuRUEfLvK1Rt2FaqidB+YNTyElpgH MsLgfElzGqmVR3eGwKnbxy98GzfpgS/4sa5qNvY3GF4juCSsVr74aTavUbqb/9bUA3j2 Kpk3NtqoyUvmm6i79ZceGfoXdPdFeivJvGbzlWCvyp789LXPr9y/tFn5WkQUChOldz45 /3fKQX54rd5RwEFsHWh9lWGMK7rFKbk3ifzYwJwQ/jDOOK7XiblZFa4I4TfC0i1HTCWQ OaP5HlEQUcUOYOkkju7jwsLMHQVIfYtEIyxlzW1XtALC/KkH8C+kXfXfHHyFQzXIAlyd s+Hw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mu4-20020a17090b388400b001fae387a66bsi4391239pjb.51.2022.09.03.00.11.46; Sat, 03 Sep 2022 00:11:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232619AbiICGvC (ORCPT + 99 others); Sat, 3 Sep 2022 02:51:02 -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 Content-Type: text/plain 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 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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) c2c_he->cpuset = bitmap_zalloc(c2c.cpus_cnt); if (!c2c_he->cpuset) - return NULL; + goto out_free_he; c2c_he->nodeset = bitmap_zalloc(c2c.nodes_cnt); if (!c2c_he->nodeset) - return NULL; + goto out_free_cpuset; c2c_he->node_stats = zalloc(c2c.nodes_cnt * sizeof(*c2c_he->node_stats)); if (!c2c_he->node_stats) - return NULL; + goto out_free_nodeset; 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); 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; } static void c2c_he_free(void *he) -- 2.17.1