From nobody Sat Feb 7 19:45:41 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4524FEB64DD for ; Fri, 23 Jun 2023 04:31:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231415AbjFWEbR (ORCPT ); Fri, 23 Jun 2023 00:31:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231175AbjFWEbO (ORCPT ); Fri, 23 Jun 2023 00:31:14 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2C6E2129 for ; Thu, 22 Jun 2023 21:31:12 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-bf34588085bso382730276.0 for ; Thu, 22 Jun 2023 21:31:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687494672; x=1690086672; h=to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=cu9nI31LEpqxG6RFF3bTH+0H9TeY5MTdZFgwWUSRFwU=; b=HDdKa5vorjtsTOrpdZyZbORmZaBWBLRNFyZz+mquVo87kCprIyIN8sJdGBbNPkAExV lZsOFohZIZYXcx+EOi3cnPYVBgXSwuRwX+NN2SyjBHY+dZhlbeFPbvDTcrUYvX4iDgND B/3N4GkPcRdJSTv8PAv+Ayi/kJFAETG/ktcG0BK1ipSkvvzQwQdd9b4hO+HNvdy4HHj0 QLMcbKt6YfIiTauaZuaOdy+BOR0vdfzOvUEXZzzZahsNRBWHTIK9DqfXmbpg8xvTmNEC ggmowdUOKFgOlKsPkUOx4gckl6EE1Qrlwe5LqX69IpEeV9d2LTWQE8ayD2XjjG87s6cJ dCXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687494672; x=1690086672; h=to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=cu9nI31LEpqxG6RFF3bTH+0H9TeY5MTdZFgwWUSRFwU=; b=eB70em7hr52/lZR8aISPZ/IRTxxVCipb3JKqcmUC7V2Art3NnOsXoM9nz5KTNvhDwP yZSb3REx+mwK8mCZqboErcXHDtiAW0O9ivu5oSBf4w/T1tpsZ/KZAJMp+057vAiWGCTv /PdlLv17O91w/jVA2zS3HxgtzNFo/Y3WnqBSApb/F5+NSUHuxkJxSDGDWSieRLbTOUQX j118zYW0NAnsJkSpLI2KBybfrdILSeJGLkoips3QD404vwRlvzyRjrsOKyIYxtKT/tYA +ZO1bOgrHEw0dIv+ghg6xwlbJCoQEIrbW3q/bkG2Bpb2OqQ0zP26xBMsyTZ+xu2YnE4j cFZg== X-Gm-Message-State: AC+VfDyeCzrK+gZynNkrmqc61HjNfmAW37PlOajWFOY96y6yFbRRBauf gvbMKpP5EH4SNHlRf0sEyllyMk2Xcx0q X-Google-Smtp-Source: ACHHUZ6Y8LjAHTkZi3zCabhg5Vde/FZX17mb7veqsintqlySiJ99zT4N14uiAb3OID4t2IMOa5kNVv3SNJgR X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:6559:8968:cdfe:35b6]) (user=irogers job=sendgmr) by 2002:a25:ab28:0:b0:bc5:2869:d735 with SMTP id u37-20020a25ab28000000b00bc52869d735mr8255983ybi.13.1687494671922; Thu, 22 Jun 2023 21:31:11 -0700 (PDT) Date: Thu, 22 Jun 2023 21:31:07 -0700 Message-Id: <20230623043107.4077510-1-irogers@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Subject: [PATCH v2] perf unwind: Fix map reference counts From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Ivan Babrou , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The result of thread__find_map is the map in the passed in addr_location. Calling addr_location__exit puts that map and so copies need to do a map__get. Add in the corresponding map__puts. Signed-off-by: Ian Rogers v2. Add missing map__put when dso is missing. Acked-by: Namhyung Kim --- tools/perf/util/unwind-libunwind-local.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tools/perf/util/unwind-libunwind-local.c b/tools/perf/util/unw= ind-libunwind-local.c index 36bf5100bad2..ebfde537b99b 100644 --- a/tools/perf/util/unwind-libunwind-local.c +++ b/tools/perf/util/unwind-libunwind-local.c @@ -419,7 +419,8 @@ static struct map *find_map(unw_word_t ip, struct unwin= d_info *ui) struct map *ret; =20 addr_location__init(&al); - ret =3D thread__find_map(ui->thread, PERF_RECORD_MISC_USER, ip, &al); + thread__find_map(ui->thread, PERF_RECORD_MISC_USER, ip, &al); + ret =3D map__get(al.map); addr_location__exit(&al); return ret; } @@ -440,8 +441,10 @@ find_proc_info(unw_addr_space_t as, unw_word_t ip, unw= _proc_info_t *pi, return -EINVAL; =20 dso =3D map__dso(map); - if (!dso) + if (!dso) { + map__put(map); return -EINVAL; + } =20 pr_debug("unwind: find_proc_info dso %s\n", dso->name); =20 @@ -476,11 +479,11 @@ find_proc_info(unw_addr_space_t as, unw_word_t ip, un= w_proc_info_t *pi, =20 memset(&di, 0, sizeof(di)); if (dwarf_find_debug_frame(0, &di, ip, base, symfile, start, map__end(ma= p))) - return dwarf_search_unwind_table(as, ip, &di, pi, - need_unwind_info, arg); + ret =3D dwarf_search_unwind_table(as, ip, &di, pi, + need_unwind_info, arg); } #endif - + map__put(map); return ret; } =20 @@ -534,12 +537,14 @@ static int access_dso_mem(struct unwind_info *ui, unw= _word_t addr, =20 dso =3D map__dso(map); =20 - if (!dso) + if (!dso) { + map__put(map); return -1; + } =20 size =3D dso__data_read_addr(dso, map, ui->machine, addr, (u8 *) data, sizeof(*data)); - + map__put(map); return !(size =3D=3D sizeof(*data)); } =20 --=20 2.41.0.162.gfafddb0af9-goog