Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1375971rwd; Thu, 8 Jun 2023 17:26:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ddIUKtAG1bAw+cqHxBAvPFIV9jMYwo7hUv+Y8/FFV3dKXdY6YJesa0f+Q4m6QkwZD4Ifu X-Received: by 2002:a17:902:cecd:b0:1b1:82a6:7c82 with SMTP id d13-20020a170902cecd00b001b182a67c82mr220425plg.27.1686270415926; Thu, 08 Jun 2023 17:26:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686270415; cv=none; d=google.com; s=arc-20160816; b=EHq5hx2oD/hdin5Ty81Gkl6hUljmBmGKPsR9CQXsHD8gVdG8HSJs06aMtFYwgWoLvv VLFvTk/n9WVQNVO19OBdUBZ9ARAOhyzwG5vhaMmXhpRNUT2xPzIBRLTNJQaDurAC6UzQ HMHeXo3mVr6c6T+QqM9A0A/SVQPefJOOs4PSOhZN4yHPfxcB4CQCU4rConDHF4VgMKfm 2P1p3nK/h1xXq8seWIygSUhUrdqO3mF4uipHIXzeNrY7mSVQbE5W+VdUqIkM0omWJzpu G5O8dsR2Tg9nKDu+0/hOPcFn0EEHHe1HOzONDbZAPYLYjpNqK+tehxg6UEO5axqxjaB/ 5v4Q== 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=d8nZzpxNSCbRXHMzfJBAp7eVEh2n3zxwlDLBqqql/Uw=; b=o6lWS21/U8abGU16pYqqtwdpmQ/j7NDAfBIN2Mgavv6Oq4xSlwP8/qihK9IHTBI4Uv xPt3jcPd58xaoRx9XhrjOCy7LDkfPbx7ZaeZWPrcA1LgI8l8SNiikdKxSGlhwOBjpB6E 2YwW7DxbGVqNdLLvzZmchVY6wpWQwvj0+fwKEA5w4p/qr2svuBVrvW6vucVcFeS113l6 rfDg0EC5tdvq7wdFC1FyTw/iS0qnNbI+3QktxJnRcfV4CkcGD/nY0CkGWiTj0fWDGTRK AmAjrj5Io4W02HyWSO7y0ewXcscCXpbmcYmfmVnIrEkOuPG0QbmuWwjQp5POA0uJo3wr W3tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=Qc8L5FoA; 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 u13-20020a17090341cd00b001b02ce8470dsi1857466ple.543.2023.06.08.17.26.43; Thu, 08 Jun 2023 17:26:55 -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=Qc8L5FoA; 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 S237226AbjFHX3k (ORCPT + 99 others); Thu, 8 Jun 2023 19:29:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237139AbjFHX3X (ORCPT ); Thu, 8 Jun 2023 19:29:23 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DFCD30F1 for ; Thu, 8 Jun 2023 16:29:22 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-bac6a453dd5so1655485276.2 for ; Thu, 08 Jun 2023 16:29:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686266961; x=1688858961; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=d8nZzpxNSCbRXHMzfJBAp7eVEh2n3zxwlDLBqqql/Uw=; b=Qc8L5FoARN90TEPW/tyBzgIkWZWMgC4vWKig+/L6A+nCr71SA5XPdM4GS9PuePF8XD vDVxVO4oJh1fDlu65LjQD5xdYcsCS7gzFhfD9C41ue5zDcLBzC2PR5pa1JLVsFMSFmwR /Gjccb+eR+2tOYSY/bXlfmbYOqiBN4vn8OyOVFLo6eGRNsJcG3cObVOUT3yOPgaWmt/e 0t3prXyPPW2p8WgFaTmsrsK+nwyFr0+bA5n3BJoyGFQxtmlXO9gnb2wQgqdg91RtnM5Y u9HM9/WhfiAzifHPJ9RsufS+aukJguBxiGtTEZZAzCE+10ItDUd4dhL1y8uJwJIsO8Rx QbrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686266961; x=1688858961; 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=d8nZzpxNSCbRXHMzfJBAp7eVEh2n3zxwlDLBqqql/Uw=; b=fQ8zqv09AwOQvMQFEMH5ktqq51kYbZTb/Ggx+OkWOp5xN6tQk8C2SS3sdCBrovxHFc D0FstONN5Bba4CWve/2nrYCvMsdEJaW11husdKKKMit4k6SFRfX7+KA1ihldiCjU9MRK xl25E7ZVCvLIk60us/d7eo1vxi+51D7KPTkEvIx+mkJCv2nzh/JN0nUmcZhfQFuzFE/e RjSbOTGmts9GQstaxYS0kmgtX0j1RoVul2CquNAomE4HPrmsX5wj1NnQOl2MA3DcquHT tfqLyXhG4E8ujejE2/fNRKqaAkRsXau/Q8GAUp6xiYbXQioTm2K0HRHAjUz/poH50a5D 065w== X-Gm-Message-State: AC+VfDw6MhFYEFwWn3R8cNY8kVy8MMe/4QTCil3iH3+Pn9cg9lHHQ9yx owIXw32v3BBMppX0kFhRs2+wmF7lk/aJ X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:c3e5:ebc6:61e5:c73f]) (user=irogers job=sendgmr) by 2002:a25:2004:0:b0:bbb:8c13:ce26 with SMTP id g4-20020a252004000000b00bbb8c13ce26mr599080ybg.11.1686266961427; Thu, 08 Jun 2023 16:29:21 -0700 (PDT) Date: Thu, 8 Jun 2023 16:28:01 -0700 In-Reply-To: <20230608232823.4027869-1-irogers@google.com> Message-Id: <20230608232823.4027869-5-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 04/26] perf maps: Make delete static, always use put 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 Address/leak sanitizer with reference count checking can identify the location of leaks, so use put rather than delete to avoid free-ing memory when the reference count is >1. Add maps__zput to ensure the variable is cleared. Signed-off-by: Ian Rogers --- tools/perf/tests/maps.c | 2 +- tools/perf/util/machine.c | 2 +- tools/perf/util/maps.c | 2 +- tools/perf/util/maps.h | 9 ++++++++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/perf/tests/maps.c b/tools/perf/tests/maps.c index 8c0eb5cf8bb5..5bb1123a91a7 100644 --- a/tools/perf/tests/maps.c +++ b/tools/perf/tests/maps.c @@ -140,7 +140,7 @@ static int test__maps__merge_in(struct test_suite *t __maybe_unused, int subtest ret = check_maps(merged3, ARRAY_SIZE(merged3), maps); TEST_ASSERT_VAL("merge check failed", !ret); - maps__delete(maps); + maps__zput(maps); return TEST_OK; } diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 5d34d60a0045..8972c852d3bd 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -248,7 +248,7 @@ void machine__exit(struct machine *machine) return; machine__destroy_kernel_maps(machine); - maps__delete(machine->kmaps); + maps__zput(machine->kmaps); dsos__exit(&machine->dsos); machine__exit_vdso(machine); zfree(&machine->root_dir); diff --git a/tools/perf/util/maps.c b/tools/perf/util/maps.c index 5ae6379a1b42..5206a6433117 100644 --- a/tools/perf/util/maps.c +++ b/tools/perf/util/maps.c @@ -171,7 +171,7 @@ struct maps *maps__new(struct machine *machine) return result; } -void maps__delete(struct maps *maps) +static void maps__delete(struct maps *maps) { maps__exit(maps); unwind__finish_access(maps); diff --git a/tools/perf/util/maps.h b/tools/perf/util/maps.h index d2963456cfbe..83144e0645ed 100644 --- a/tools/perf/util/maps.h +++ b/tools/perf/util/maps.h @@ -57,13 +57,20 @@ struct kmap { }; struct maps *maps__new(struct machine *machine); -void maps__delete(struct maps *maps); bool maps__empty(struct maps *maps); int maps__clone(struct thread *thread, struct maps *parent); struct maps *maps__get(struct maps *maps); void maps__put(struct maps *maps); +static inline void __maps__zput(struct maps **map) +{ + maps__put(*map); + *map = NULL; +} + +#define maps__zput(map) __maps__zput(&map) + static inline struct rb_root *maps__entries(struct maps *maps) { return &RC_CHK_ACCESS(maps)->entries; -- 2.41.0.162.gfafddb0af9-goog