Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1349189rwd; Thu, 8 Jun 2023 16:58:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4fYkBvAxxeHVOAPZLNP/R9woIoJj8ho7yxW/5z3podB9E4bfYXn9+7Jzx42h2jVGo8sEB+ X-Received: by 2002:a17:902:b585:b0:1b2:1825:813e with SMTP id a5-20020a170902b58500b001b21825813emr6935897pls.5.1686268721640; Thu, 08 Jun 2023 16:58:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686268721; cv=none; d=google.com; s=arc-20160816; b=h2c6e7iHkOtktewNQXjZj95nDHM6lo4ojG7E1IaMNluKA97tUPDzUWFQw0GJ5NseTk K8L/wvi9bXJL72PDMI+pRrJHuXRuQofCyydqujpV5eYGkigkRcqpx1uwNBVLw/+tjTDb dpuRNPvvmS2TxqDrJCfsCKwUXHI+u9R7EiXj+ELkUNALkdEmRDD/pGJtqrqJCF/7X+Ir IZNxKqFxB1aWcnvuKAMnbgTaKBhynijVXdXdrgP75oT3BQo+QtHrrgCe7rMzfdmv6hsh pt73VRVuArz70eFVtpDbYPTld8b5M9U0rmyvDHuDocboxEK1dC2exHsiDEJ9/ILljAXP v73g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=HYQaZtuHl/SxeGLPx3KYJtDk+ilAjOX/gkAdD1/27NA=; b=tB3wxemHNdJw33SN5AeK/h+fr7k+EHvKEaCAJCsM7+54Hx/1pAj03loe5RsrRAXfUA Lbt07tXLYBTWhp+/scXabkhUNJeqhsG8fgG9+Kv5D9Cl+pf2N5G+WGqukoM472DrnGRm tmj3FnFEpMVVjY3C4/2v2BjkMKBCeE6FBVLDrHDqAf8keOIii0CXmCNTCvBGKc32ZJgV csbQX1VSP3BSxLFAdml6WoTdqEf9xr7PqTTUzgo46PKUNLEwJjHWrNiBLncK2mssY/4b IiGTpA+928BrIG0z0VddMPRStZ889vLW6UEPZdiqL+Y5FC1Ig4yuS6YvC9IQefG4tH1L 0HDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=fBJl3wcz; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jx7-20020a170903138700b001b04903dd73si1688385plb.120.2023.06.08.16.58.11; Thu, 08 Jun 2023 16:58:41 -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; dkim=pass header.i=@google.com header.s=20221208 header.b=fBJl3wcz; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237482AbjFHXaX (ORCPT + 99 others); Thu, 8 Jun 2023 19:30:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237363AbjFHX3s (ORCPT ); Thu, 8 Jun 2023 19:29:48 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCD3330FD for ; Thu, 8 Jun 2023 16:29:37 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5655d99da53so25389627b3.0 for ; Thu, 08 Jun 2023 16:29:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686266976; x=1688858976; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=HYQaZtuHl/SxeGLPx3KYJtDk+ilAjOX/gkAdD1/27NA=; b=fBJl3wcz+FnbBgSbRGxXixBnK3jNLSuIKoFf166vI/z37Q4wIcVYPmW50NKtSp9UgF rvr7Vycm6Wb545G0pPRanvDdHAxrKWNJYkGc8Cmt8RYCACXwUGF/iIgTa75YwhW6PV8M mKbs+2jj1XRyRcyBNZLzm3S68U4QfnBSrHCRrxCTe8VZcEJxXqnwaqFgKSsS9LhNsvdM tl5boNkQ9DOfVLIFy8QP8zuGyB+ZRB6QpW44Y8AgMfKg/dSL2Zi7fb7dxcr7cS8GtvBr vUG+miDiAkxObR0Wne3r2jVUorOhIbFbcFXuzN7/NEbTmZrBQnQK7BN7zEnfzQDZf8N8 FOdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686266976; x=1688858976; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=HYQaZtuHl/SxeGLPx3KYJtDk+ilAjOX/gkAdD1/27NA=; b=a0J5PFvRSZ+AeNTXMv4tPWYDONmwo7VPS4LfVeTJgCJ6I3Cd8KQO6edaUROR96yvD8 AjvVCD3cWYsEO5hknXgmx0dF2Zcu8VvVdDhsB8W16IkqUEO2Tu82jgeqiEyKyhniTFif KFkJt0UAkxW4+/dJWtYZh3V1R01YngsJcnDZFjz/lAYF0J6DX1T1Zj422yDaR6RPO/7R RZfNFBtsJVz8QjrTO4LD2oF7qDob6ukCSIz+pZA8hJ0BEMhT1IX6RvT52z1xOLv5rZzL v+/MQDIbcIhaHXhPnzo9acU8nXy+g20tWQ9cROO0uiYI5FyOcnXoUclJjp3y8W4zlHxD +cnA== X-Gm-Message-State: AC+VfDwlYX4J70XabdsQ4jXB30e0qcOVvu0MIUkhDPK6NWYRjeQ7wueu PA75b4xR7qU6y4svXP0k23NjxM4L2BlX X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:c3e5:ebc6:61e5:c73f]) (user=irogers job=sendgmr) by 2002:a05:690c:2901:b0:55d:9e7c:72c0 with SMTP id eg1-20020a05690c290100b0055d9e7c72c0mr648158ywb.0.1686266976710; Thu, 08 Jun 2023 16:29:36 -0700 (PDT) Date: Thu, 8 Jun 2023 16:28:07 -0700 In-Reply-To: <20230608232823.4027869-1-irogers@google.com> Message-Id: <20230608232823.4027869-11-irogers@google.com> Mime-Version: 1.0 References: <20230608232823.4027869-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Subject: [PATCH v2 10/26] perf header: Ensure bitmaps are freed From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Suzuki K Poulose , "Naveen N. Rao" , Kan Liang , German Gomez , Ali Saidi , Jing Zhang , Athira Rajeev , Miguel Ojeda , ye xingchen , Liam Howlett , Dmitrii Dolgov <9erthalion6@gmail.com>, Yang Jihong , K Prateek Nayak , Changbin Du , Ravi Bangoria , Sean Christopherson , Andi Kleen , "Steinar H. Gunderson" , Yuan Can , Brian Robbins , liuwenyu , Ivan Babrou , Fangrui Song , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, coresight@lists.linaro.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL 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 memory_node bitmaps need a bitmap_free to avoid memory leaks. Caught by leak sanitizer. Signed-off-by: Ian Rogers --- tools/perf/util/header.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index d85b39079c31..3db7c1fae71e 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -1389,6 +1389,14 @@ static int memory_node__read(struct memory_node *n, unsigned long idx) return 0; } +static void memory_node__delete_nodes(struct memory_node *nodesp, u64 cnt) +{ + for (u64 i = 0; i < cnt; i++) + bitmap_free(nodesp[i].set); + + free(nodesp); +} + static int memory_node__sort(const void *a, const void *b) { const struct memory_node *na = a; @@ -1449,7 +1457,7 @@ static int build_mem_topology(struct memory_node **nodesp, u64 *cntp) *nodesp = nodes; qsort(nodes, cnt, sizeof(nodes[0]), memory_node__sort); } else - free(nodes); + memory_node__delete_nodes(nodes, cnt); return ret; } @@ -1516,7 +1524,7 @@ static int write_mem_topology(struct feat_fd *ff __maybe_unused, } out: - free(nodes); + memory_node__delete_nodes(nodes, nr); return ret; } -- 2.41.0.162.gfafddb0af9-goog