Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4052275ybg; Fri, 25 Oct 2019 12:37:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqxIVAwAN2k/B21M3snN5oqmbevH/ejE7TXEdV7h/JBYCEOvp/rsYdVMTKt6XgIp/ZAcoa9O X-Received: by 2002:a50:eb81:: with SMTP id y1mr5876941edr.119.1572032240649; Fri, 25 Oct 2019 12:37:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572032240; cv=none; d=google.com; s=arc-20160816; b=bzktxoGiDlZBLWjmStzqT2hd4rMLb7V082JEAmGVbOetVysquNdEouel1XqZNeHlF/ 28auXZ8N3L4YXjRJonpVP9FBEZFy3L1mBF23m9Z0JdFKTp3+c+29RTX1FhbdUJXWXLYe vhQINgbFnnCoxYZVajb6fySchkXAwtIxiOdXpOicblqR7Dhra5XcWuVK7fKm4XF6H4dh 4QkCaBPEMpeLpuajt+nb6LPM4QRSw5v16vosiJQjZVMLIbpUCvcQKzYmyVXDZzECAKHl 7B+tLi/JeY2p2SKKImJb6SWrvFfQ1C5EKLUzWCKfXGgZbcwyRHgwgIPJuzREsNr5rUDF i+EA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:mime-version:user-agent:date:message-id:subject :from:cc:to; bh=ySYAuHYDqSYMKLMaq3uUQvHJe5iupUVeaoPu3WPz5SU=; b=H871sZuUR1KSJ1w68YikoVw37kf7LAJ+NryNln+Qb0AZLVHyOWN1N5mYJGBjlM8Lgy ymhpAOJsXBM+SKHKBnzIOtsGKdY+gQSWKGNAfO5NiHoBJC/uK25DM31kIf3eoRC8vOGM xlTVmw/AgE4l+/B01hXk3gmS1OxNvEoB3lJKRf2XS40A9ZKxd9KXBTuDkuCAhWyqa6Av 239hdDOFi77mHhaM46p7sVb8qLUYWCsBZWeWtFQ8WQ+1u5aC/ODQZoRqfB8a/+Elj+SJ gWSKGt8gK+L1bEcT+kcQ3c3L0VshQqUOKDIvl1Rms2seo/mdmF7GAMrPjzxPj992SLzK ixVg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id rk26si1798696ejb.303.2019.10.25.12.36.57; Fri, 25 Oct 2019 12:37:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2408864AbfJYJnA (ORCPT + 99 others); Fri, 25 Oct 2019 05:43:00 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:39366 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2408858AbfJYJnA (ORCPT ); Fri, 25 Oct 2019 05:43:00 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 02B03FEEB462496965CC; Fri, 25 Oct 2019 17:42:59 +0800 (CST) Received: from [127.0.0.1] (10.177.251.225) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.439.0; Fri, 25 Oct 2019 17:42:49 +0800 To: , , , , , , CC: , "hushiyuan@huawei.com" , "linfeilong@huawei.com" From: Yunfeng Ye Subject: [PATCH] perf c2c: Fix memory leak in c2c_he_zalloc() Message-ID: <9d5f26f8-9429-bcb6-d491-cb789f761ea2@huawei.com> Date: Fri, 25 Oct 2019 17:42:47 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.251.225] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A memory leak in c2c_he_zalloc() is found by visual inspection. Fix this by adding memory free on the error paths in c2c_he_zalloc(). Fixes: 7f834c2e84bb ("perf c2c report: Display node for cacheline address") Fixes: 1e181b92a2da ("perf c2c report: Add 'node' sort key") Signed-off-by: Yunfeng Ye --- 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 e69f44941aad..ad7d38a9dcbe 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -138,21 +138,29 @@ static void *c2c_he_zalloc(size_t size) c2c_he->cpuset = bitmap_alloc(c2c.cpus_cnt); if (!c2c_he->cpuset) - return NULL; + goto free_c2c_he; c2c_he->nodeset = bitmap_alloc(c2c.nodes_cnt); if (!c2c_he->nodeset) - return NULL; + goto free_cpuset; c2c_he->node_stats = zalloc(c2c.nodes_cnt * sizeof(*c2c_he->node_stats)); if (!c2c_he->node_stats) - return NULL; + goto free_nodeset; init_stats(&c2c_he->cstats.lcl_hitm); init_stats(&c2c_he->cstats.rmt_hitm); init_stats(&c2c_he->cstats.load); return &c2c_he->he; + +free_nodeset: + free(c2c_he->nodeset); +free_cpuset: + free(c2c_he->cpuset); +free_c2c_he: + free(c2c_he); + return NULL; } static void c2c_he_free(void *he) -- 2.7.4