From patchwork Thu Dec 7 08:16:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yicong Yang X-Patchwork-Id: 175013 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4628226vqy; Thu, 7 Dec 2023 00:21:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IGLraJET24JA7qqlC1ynYmgMQhKVs2f33ZuXllrpJT1SorW8fnvQ59KlKw5c5f0Jd2r8fhb X-Received: by 2002:a05:6a00:3317:b0:6ce:4047:7a6b with SMTP id cq23-20020a056a00331700b006ce40477a6bmr2622933pfb.28.1701937302509; Thu, 07 Dec 2023 00:21:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701937302; cv=none; d=google.com; s=arc-20160816; b=FC1l7Mjyp8iU35Xu2xTOhcdUaXDfek8TuQHZXMEdthf6s6xYYxIvELtLUo5FXl9NtA tdhndW+JDcALJtYl9uZsSFU3vnGff9jNMhwsG3n7DINy8ro3i2aHmmQ8yvf88gj70/QN aDL4W2cTDSHoP6sVYQUYG/QcH+4/lf029EMEww4hVkzwRRlyAzY1HS0YZIo7PUiR53CR gr1XpqgTe7w6qx7oDckK1rYwxrmAUuRVyAKpfeR8T6zuwjqJVWV3oUuLIfNmHu1ZLFXL kNAfNEttyiCk9uk2cOvc3NJcY1uIcPZCad8ZcOCDe9s8YTRufbrac/UUFe5hBgxsuZ4Q OnlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=EzCwkMJkxcoSloFEhiEZ6qHz2l6qYDL7+Qpey3PBj40=; fh=K06Jco0a5Hd2X5wdXGCplGw8z+4vmGZK/avjKpeDM8o=; b=Z35WxWtRLyMdSbZwmFGAU/b9uRWVjkcsQMeiEZyT550OgnbxhMFWQKpypLdoOo0Pe6 7/X43p1zzL6i9W7tiLNlIMIPJkojpgpWMc7AofpSHGTdTH1yGpiJeqBGMcnIdbxtUO5I lCJ1qAzEN61qn6sCGr/eDq2MxXLhPnWNPEedTJCe5a7jWCdgL1hHjMs3yKs/OmUgrX18 ESSC5/RmSXzDzjts1LdY8LV5t6ns4zg1InbUy80uWXWCLLmPKVmv6I12pM+/z2JTpiXQ 4IBgQ/2tuawfYbfppMSUbjbjRNLXO4+kar7qToaMewQ1x8rYQL7OyiZhE5Nd/qn391o4 eSZg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id e3-20020a654783000000b005c68d9545c7si795082pgs.334.2023.12.07.00.21.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 00:21:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 632AA8098FE6; Thu, 7 Dec 2023 00:21:32 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231551AbjLGIUv (ORCPT + 99 others); Thu, 7 Dec 2023 03:20:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231829AbjLGIUS (ORCPT ); Thu, 7 Dec 2023 03:20:18 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D26A10DE; Thu, 7 Dec 2023 00:20:22 -0800 (PST) Received: from canpemm500009.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Sm6X82K1wz14LrL; Thu, 7 Dec 2023 16:15:20 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by canpemm500009.china.huawei.com (7.192.105.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 7 Dec 2023 16:20:19 +0800 From: Yicong Yang To: , , , , , , , , , , CC: , , , Subject: [PATCH 1/2] perf header: Fix one memory leakage in perf_event__fprintf_event_update() Date: Thu, 7 Dec 2023 16:16:34 +0800 Message-ID: <20231207081635.8427-2-yangyicong@huawei.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20231207081635.8427-1-yangyicong@huawei.com> References: <20231207081635.8427-1-yangyicong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.165.33] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To canpemm500009.china.huawei.com (7.192.105.203) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 07 Dec 2023 00:21:32 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784610608403615640 X-GMAIL-MSGID: 1784610608403615640 From: Yicong Yang When dump the raw trace by `perf report -D` ASan reports a memory leakage in perf_event__fprintf_event_update(). It shows that we allocated a temporary cpumap for dumping the CPUs but doesn't release it and it's not used elsewhere. Fix this by free the cpumap after the dumping. Fixes: c853f9394b7b ("perf tools: Add perf_event__fprintf_event_update function") Cc: Jiri Olsa Signed-off-by: Yicong Yang Acked-by: Namhyung Kim --- tools/perf/util/header.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index e86b9439ffee..7190f39ccd13 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -4369,9 +4369,10 @@ size_t perf_event__fprintf_event_update(union perf_event *event, FILE *fp) ret += fprintf(fp, "... "); map = cpu_map__new_data(&ev->cpus.cpus); - if (map) + if (map) { ret += cpu_map__fprintf(map, fp); - else + perf_cpu_map__put(map); + } else ret += fprintf(fp, "failed to get cpus\n"); break; default: