From patchwork Wed Jul 19 20:29:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 122831 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2707370vqt; Wed, 19 Jul 2023 14:05:56 -0700 (PDT) X-Google-Smtp-Source: APBJJlHiBkcQDK0WkXXa7CAgM1a6N4/K7V/Hhjf3S1k8O7yF1UEnoYiyy/tJCY0UywUXxqy2R0RE X-Received: by 2002:a17:906:290:b0:992:3897:1985 with SMTP id 16-20020a170906029000b0099238971985mr3041195ejf.43.1689800755756; Wed, 19 Jul 2023 14:05:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689800755; cv=none; d=google.com; s=arc-20160816; b=f2Wcp+TKS/ZPIuLw2lULVNZs9JH0+gACuF1OixRIZ58PYPD272ZI/0Sof9mh35cbX9 ItWi/W9uWBzDLU0MUSuJXRkQIQ4QU2pb/B7WU3ISlnnMwhx4i4xGEPYr0/SSZsNjV+Gc o7aOt4D47crqipwB9NP+FKIPTGdCj8hsWmCKIyySxcetiR3AggG3b6nGs01zgaJ/4d0e iqZ21OBwi+DBmk4srLTwN0PQepjE4TPFKN4Uml3Em1/vrmA5h9Kunk7lrxcb18Z1eRZc lqjlSTsFs6RHATI4N3qhd0GvmTWbHCvww4J2iQps5CKtoJi2mz3YeDhOaszLfO/Zdzut 4hYg== 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 :dkim-signature; bh=IXT7UYfnSbJNyHxFpUiXrQuyVZPPhMZClE6jW2HfotI=; fh=GZ4eSIeu5yUrjQDUyFDhKHpL6itJkKQ8QAaBkaJW/mM=; b=rF+MxwZJuqnzbIRyLkrWAfGYX2hjjCxBlYkPjeMKEZfscS6IwlpWbYTAucfDFWxJMj cBkkdROtooCioD0MV43JYqrwKO+mz+BfoHABC5WvHdYcSV0VGcA4XYHk44W+I9VNTZWk ACk8rbSRltAuGQfBl3X2DZed+TplIZhZp7/pUKjSRWHkGO8u3wJoLPjc8nYxNuW+Mj3o EfQgi7MR6wXvqV2XttHOnhTwt43kY14n2ND1MkKixSwt5zqr+FAHC/nNnV67Y07X3b5O XtAIHxHcmLc+QUr0gGf/VQCjTQexkAWs9Qk1meEGOZnI+ybcfBtFvXoC717kuKWR+usc yfkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uEDfoUsm; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k16-20020a1709065fd000b009930294ae72si3703490ejv.293.2023.07.19.14.05.31; Wed, 19 Jul 2023 14:05: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=@kernel.org header.s=k20201202 header.b=uEDfoUsm; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229732AbjGSUak (ORCPT + 99 others); Wed, 19 Jul 2023 16:30:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231467AbjGSUae (ORCPT ); Wed, 19 Jul 2023 16:30:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D6EE2D6B; Wed, 19 Jul 2023 13:30:03 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 20A0F617E4; Wed, 19 Jul 2023 20:30:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 040E5C433C9; Wed, 19 Jul 2023 20:29:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689798602; bh=goX2lDmeZF8/0WGZE1xE1qdjbTmkUWJAnLQ7R0lm72Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uEDfoUsmNHbSkzHppAbTaO7Bjutnh+Mbk65s/ZGip7I6hA5YOH15YX2cW4XZ6eJpF GMJkoUgXmOYSv+8MOjJALcIVIxVn6dQYiGhsRkyrHxF1+rEoUd/ddumTdQJ49py2Is t2sJFU/CKw/CpsNOL3FFNvriX0o0d1FlfUa9Ud8Jnx0UNDcoGhdfTZHQOSzZC0H6sr 9Sht3vtL4lMY8OW/GKYlpV9d8qXzb3auxYatV+sgHWf4IBcAaQ8tBTYZXo6pXKiRue 3QHErko/kiy0D/91MQrXtIwJnKZeurmpc4srG+kFVb3JknGMrbC5tqBBfGFa6aQruu 83MLGZFrO5XBQ== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , Kate Carcia , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo Subject: [PATCH 1/6] perf evsel: Free evsel->filter on the destructor Date: Wed, 19 Jul 2023 17:29:46 -0300 Message-ID: <20230719202951.534582-2-acme@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230719202951.534582-1-acme@kernel.org> References: <20230719202951.534582-1-acme@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771884517397715422 X-GMAIL-MSGID: 1771884517397715422 From: Arnaldo Carvalho de Melo Noticed with: make EXTRA_CFLAGS="-fsanitize=address" BUILD_BPF_SKEL=1 CORESIGHT=1 O=/tmp/build/perf-tools-next -C tools/perf install-bin Direct leak of 45 byte(s) in 1 object(s) allocated from: #0 0x7f213f87243b in strdup (/lib64/libasan.so.8+0x7243b) #1 0x63d15f in evsel__set_filter util/evsel.c:1371 #2 0x63d15f in evsel__append_filter util/evsel.c:1387 #3 0x63d15f in evsel__append_tp_filter util/evsel.c:1400 #4 0x62cd52 in evlist__append_tp_filter util/evlist.c:1145 #5 0x62cd52 in evlist__append_tp_filter_pids util/evlist.c:1196 #6 0x541e49 in trace__set_filter_loop_pids /home/acme/git/perf-tools/tools/perf/builtin-trace.c:3646 #7 0x541e49 in trace__set_filter_pids /home/acme/git/perf-tools/tools/perf/builtin-trace.c:3670 #8 0x541e49 in trace__run /home/acme/git/perf-tools/tools/perf/builtin-trace.c:3970 #9 0x541e49 in cmd_trace /home/acme/git/perf-tools/tools/perf/builtin-trace.c:5141 #10 0x5ef1a2 in run_builtin /home/acme/git/perf-tools/tools/perf/perf.c:323 #11 0x4196da in handle_internal_command /home/acme/git/perf-tools/tools/perf/perf.c:377 #12 0x4196da in run_argv /home/acme/git/perf-tools/tools/perf/perf.c:421 #13 0x4196da in main /home/acme/git/perf-tools/tools/perf/perf.c:537 #14 0x7f213e84a50f in __libc_start_call_main (/lib64/libc.so.6+0x2750f) Free it on evsel__exit(). Cc: Adrian Hunter Cc: Ian Rogers Cc: Jiri Olsa Cc: Namhyung Kim Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/evsel.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 762e2b2634a5532a..e41bc4d9925f69a4 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1474,6 +1474,7 @@ void evsel__exit(struct evsel *evsel) perf_thread_map__put(evsel->core.threads); zfree(&evsel->group_name); zfree(&evsel->name); + zfree(&evsel->filter); zfree(&evsel->pmu_name); zfree(&evsel->group_pmu_name); zfree(&evsel->unit); From patchwork Wed Jul 19 20:29:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 122836 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2712742vqt; Wed, 19 Jul 2023 14:16:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlFE9kwP4sJtIc9+JfLExrXW7DFDby/rH0Ta0ov3VFaKHxiOotYDyHt773/0WgIQqhYJFivN X-Received: by 2002:a05:6a00:3996:b0:666:ecf4:ed6d with SMTP id fi22-20020a056a00399600b00666ecf4ed6dmr3892091pfb.18.1689801402701; Wed, 19 Jul 2023 14:16:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689801402; cv=none; d=google.com; s=arc-20160816; b=uQqC5WPDMt5CzAE8+BeMKSMnZoDBlxwZMHmH00oqRfAwa7QV8ceNEeBqQ1xXsVBu5N Ldq5L954CnkLhk2wfwY7WnPy5EUu0TyDXjqfZOtYSzUtAgE2fXxZP7LARNUQzUuSHPAh mqwKTsn66UHuWHchyC2ZWuwQHl2sMTZ653GQsfu/Sm1zZz+snNXHrgNfevo6x+Z2/App fkmOhLKgNxZfYUMdYpX+ZjUimNu0IVR8WfcAQF/Pq2EypqIPKzusQrO7i0j1/DkCv/g4 voKgjBOXyDDGbkAp5tyqCOAcQG+YbCrtWg9zBY800/iFEtVuwgI0xL9/i4y4xNN35L3t lTrA== 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 :dkim-signature; bh=hjzRtno2QRvSHOFOPFqObOUXVNYMdykbtcCuqjw9c+w=; fh=GZ4eSIeu5yUrjQDUyFDhKHpL6itJkKQ8QAaBkaJW/mM=; b=QhAIU2vmxLJsHGO5gwRyo2+62oIG9KqAYGtVxareFx5fn512YMvVPicbOlWIIFXlKX 4cvTnFjy7Ya2WDHaGHF+jL5t85Jew3k0CUORLHfRQj/dRVeJYP97z1g6FRFwrNdXJuls 9dgWmQcr/WHwKQV2g8/MICLvOD/4ewahXZcPfDKvvfwrBzx3OB/UpPHjWlwZflJK1QmC EMb+/O//t2ewNaXKs5HJzl8LDA3jD6YXFGY/q16iDnJ5nj/iA/2rb5S0Hi1hRh1JuCzE FXVVWOF3Bum2uQoIz2vhVR1bQucrcLLkg78HQjGqGQ/SMM2QdLrpFXWq2sjgyHzkG3Mr JKHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eLuzMdK3; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f19-20020a635553000000b0055fe860330bsi4068492pgm.205.2023.07.19.14.16.29; Wed, 19 Jul 2023 14:16:42 -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=@kernel.org header.s=k20201202 header.b=eLuzMdK3; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231310AbjGSUcP (ORCPT + 99 others); Wed, 19 Jul 2023 16:32:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231303AbjGSUcK (ORCPT ); Wed, 19 Jul 2023 16:32:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3DB2268D; Wed, 19 Jul 2023 13:31:38 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1BC3B61828; Wed, 19 Jul 2023 20:30:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 044B0C433C7; Wed, 19 Jul 2023 20:30:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689798605; bh=BRr5z+/T35P0lcuwuDmZU0RVzfr8a7oe2vprcDbwtgo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eLuzMdK34w6j5GXTkBaVLYSnwgF5Bu10EGq7KZeJhZlqE3HnYBLVm4IEb4roVyTwh zaRJeQThJ4AwDxoFLo0FHsKfpHb/hroAwkE9/sVSKF+KehTyNo1IXC9GgO16PNNwSo HBP8mGWr+glXWHk2ty88qBhpLeRNDRCESsWRzJ5g08Mh0YRpsPldwoJMrGo9TmUciG +utjq8ZVV6cRUKH6fodglvjSjZPdTtx5cMD7pQPNig3MKUkA0/xdJ4AK+8/zSQ0IS4 mq0EjGOhSMVIPY1VS4KDrmfwBkQ4g2fjvDt7VpeYtNF26daSz6+Q/2j2sJr+nbs9JD zo/T8JyH7hO/A== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , Kate Carcia , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo Subject: [PATCH 2/6] perf thread: Allow tools to register a thread->priv destructor Date: Wed, 19 Jul 2023 17:29:47 -0300 Message-ID: <20230719202951.534582-3-acme@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230719202951.534582-1-acme@kernel.org> References: <20230719202951.534582-1-acme@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771885195691530859 X-GMAIL-MSGID: 1771885195691530859 From: Arnaldo Carvalho de Melo So that when thread__delete() runs it can be called and free stuff tools stashed into thread->priv, like 'perf trace' does and will use this new facility to plug some leaks. Cc: Adrian Hunter Cc: Ian Rogers Cc: Jiri Olsa Cc: Namhyung Kim Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/thread.c | 11 +++++++++++ tools/perf/util/thread.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index 0b166404c5c365cf..35dd4e716e411da9 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c @@ -80,6 +80,13 @@ struct thread *thread__new(pid_t pid, pid_t tid) return NULL; } +static void (*thread__priv_destructor)(void *priv); + +void thread__set_priv_destructor(void (*destructor)(void *priv)) +{ + thread__priv_destructor = destructor; +} + void thread__delete(struct thread *thread) { struct namespaces *namespaces, *tmp_namespaces; @@ -112,6 +119,10 @@ void thread__delete(struct thread *thread) exit_rwsem(thread__namespaces_lock(thread)); exit_rwsem(thread__comm_lock(thread)); thread__free_stitch_list(thread); + + if (thread__priv_destructor) + thread__priv_destructor(thread__priv(thread)); + RC_CHK_FREE(thread); } diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h index 9068a21ce0fa1b0f..e79225a0ea46b789 100644 --- a/tools/perf/util/thread.h +++ b/tools/perf/util/thread.h @@ -71,6 +71,8 @@ struct thread *thread__new(pid_t pid, pid_t tid); int thread__init_maps(struct thread *thread, struct machine *machine); void thread__delete(struct thread *thread); +void thread__set_priv_destructor(void (*destructor)(void *priv)); + struct thread *thread__get(struct thread *thread); void thread__put(struct thread *thread); From patchwork Wed Jul 19 20:29:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 122833 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2708810vqt; Wed, 19 Jul 2023 14:08:33 -0700 (PDT) X-Google-Smtp-Source: APBJJlH3dQli1BoJ0nIe/ZVNIIXk8S5pvWsB3WNXr5rxvziAJninCydIm/4eeOOBz6pwAG8RrUlS X-Received: by 2002:a17:906:535d:b0:965:fb87:4215 with SMTP id j29-20020a170906535d00b00965fb874215mr3197390ejo.15.1689800912864; Wed, 19 Jul 2023 14:08:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689800912; cv=none; d=google.com; s=arc-20160816; b=W6+TG5IWsIPSu8s6lJlJSz4a5I22u00Sd3miQ5lkp1q9Q8ziUeF9SNkOwjTlNQP9j1 APSJZ/ZiibbH0lLWj4DxzwgDa6TnSB/sYGqGN7niurRtLI943oyzVS8fDj0thomUHU4V Nw7PLE6lBjk7BUcqHAGjmA4lg/wYKug+MHdIQh97cajnoJmqE1rgOszkYEjeefhU/Gxy wzeyAMmC5M7mk3xz3ISjzcuEpFTJrjL2Gq8nEBn67KCHu5I4ccRF4VQplYlljaf/d5DA GdmgThSr0+ksc/oX8qMX1t3YZe7ko8RVoVY9fzoaHyCFM7u42sfl9xAHdzlVaGy/nOjC 7FFA== 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 :dkim-signature; bh=d4fbHGm9zdUBnwXQ4I+Ss7cmEz57myy928hoLuKZ12U=; fh=GZ4eSIeu5yUrjQDUyFDhKHpL6itJkKQ8QAaBkaJW/mM=; b=eBrMfDWmXPOkXuNp3b0u1C3CskvODSnHSCr6ciuuDd4Zr/VpDt+AZUdJ1RVgRV9F5V Skk27+rKTGsTRdhrETSF5zewT/+XkrRwNzvFk3wM4fzlbrN+vC5rPWSHqYZNWDlN60Cf L/vRX9/57bEW2KMCx7gDZ0/Gk4xmLSR5dHVjM0HzixI8IPZuw9n77v8nBGHkhuI40G4m 4Jb6H2Hh7mJSTNGkeGSg3cx2AVUBh7w/hpLS/h16AWq5smYCkbQGv9VLpTy3/bfm1hSk dlABtXYxD009iCa5Q0xuqAvEmLOg52asAreHJ6u8nSOlXfNW3HysqNyRhXnamI2eXY9E rH0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="D0/lu3ji"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a20-20020a1709062b1400b00992ac6d8893si3429308ejg.792.2023.07.19.14.08.07; Wed, 19 Jul 2023 14:08:32 -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=@kernel.org header.s=k20201202 header.b="D0/lu3ji"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230143AbjGSUbz (ORCPT + 99 others); Wed, 19 Jul 2023 16:31:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230182AbjGSUbn (ORCPT ); Wed, 19 Jul 2023 16:31:43 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58EDC26B3; Wed, 19 Jul 2023 13:31:16 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 17868617CB; Wed, 19 Jul 2023 20:30:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0187AC433CC; Wed, 19 Jul 2023 20:30:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689798608; bh=41NMeb8O2kAkF7/Aw6IzBaxDpGR5wEviXzLI33tbCk8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D0/lu3ji6RGVTyr4iG6scK5nJLhPVaMXRpEXUiYN/jZaqfRi0WGKjzSF5b+XFU+kk ebHgR7hcAfZIDGQ5s1SdNLKwgHwHnL4L3t07iVWuCTP1P8EWUV6zqBUc4RPfVUzb4y 0zlteOaIoRjGZsehXkAWPjhpTMDBTCS0Opob8jGozF5frbMaDoPV+1hAwDHRqGJzS0 BU4u1vP2gegg34vpFUPeS8kPVUbl68ohnMLN85S2wR+XWZlLB7CdMRMWzsmoAzx2Dd HVmMNA8v1HSXr3a5wAKSOYcNVT+NlHaV3MivoBFVlf7/7DP+68sJixQSJUMOxyLHE4 CHsdzjY+DpNcQ== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , Kate Carcia , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo Subject: [PATCH 3/6] perf trace: Register a thread priv destructor Date: Wed, 19 Jul 2023 17:29:48 -0300 Message-ID: <20230719202951.534582-4-acme@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230719202951.534582-1-acme@kernel.org> References: <20230719202951.534582-1-acme@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771884682033597429 X-GMAIL-MSGID: 1771884682033597429 From: Arnaldo Carvalho de Melo To plug these leaks detected with: $ make EXTRA_CFLAGS="-fsanitize=address" BUILD_BPF_SKEL=1 CORESIGHT=1 O=/tmp/build/perf-tools-next -C tools/perf install-bin ================================================================= ==473890==ERROR: LeakSanitizer: detected memory leaks Direct leak of 112 byte(s) in 1 object(s) allocated from: #0 0x7fdf19aba097 in calloc (/lib64/libasan.so.8+0xba097) #1 0x987836 in zalloc (/home/acme/bin/perf+0x987836) #2 0x5367ae in thread_trace__new /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:1289 #3 0x5367ae in thread__trace /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:1307 #4 0x5367ae in trace__sys_exit /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:2468 #5 0x52bf34 in trace__handle_event /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:3177 #6 0x52bf34 in __trace__deliver_event /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:3685 #7 0x542927 in trace__deliver_event /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:3712 #8 0x542927 in trace__run /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:4055 #9 0x542927 in cmd_trace /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:5141 #10 0x5ef1a2 in run_builtin /home/acme/git/perf-tools-next/tools/perf/perf.c:323 #11 0x4196da in handle_internal_command /home/acme/git/perf-tools-next/tools/perf/perf.c:377 #12 0x4196da in run_argv /home/acme/git/perf-tools-next/tools/perf/perf.c:421 #13 0x4196da in main /home/acme/git/perf-tools-next/tools/perf/perf.c:537 #14 0x7fdf18a4a50f in __libc_start_call_main (/lib64/libc.so.6+0x2750f) Direct leak of 2048 byte(s) in 1 object(s) allocated from: #0 0x7f788fcba6af in __interceptor_malloc (/lib64/libasan.so.8+0xba6af) #1 0x5337c0 in trace__sys_enter /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:2342 #2 0x52bfb4 in trace__handle_event /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:3191 #3 0x52bfb4 in __trace__deliver_event /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:3699 #4 0x542883 in trace__deliver_event /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:3726 #5 0x542883 in trace__run /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:4069 #6 0x542883 in cmd_trace /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:5155 #7 0x5ef232 in run_builtin /home/acme/git/perf-tools-next/tools/perf/perf.c:323 #8 0x4196da in handle_internal_command /home/acme/git/perf-tools-next/tools/perf/perf.c:377 #9 0x4196da in run_argv /home/acme/git/perf-tools-next/tools/perf/perf.c:421 #10 0x4196da in main /home/acme/git/perf-tools-next/tools/perf/perf.c:537 #11 0x7f788ec4a50f in __libc_start_call_main (/lib64/libc.so.6+0x2750f) Indirect leak of 48 byte(s) in 1 object(s) allocated from: #0 0x7fdf19aba6af in __interceptor_malloc (/lib64/libasan.so.8+0xba6af) #1 0x77b335 in intlist__new util/intlist.c:116 #2 0x5367fd in thread_trace__new /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:1293 #3 0x5367fd in thread__trace /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:1307 #4 0x5367fd in trace__sys_exit /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:2468 #5 0x52bf34 in trace__handle_event /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:3177 #6 0x52bf34 in __trace__deliver_event /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:3685 #7 0x542927 in trace__deliver_event /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:3712 #8 0x542927 in trace__run /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:4055 #9 0x542927 in cmd_trace /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:5141 #10 0x5ef1a2 in run_builtin /home/acme/git/perf-tools-next/tools/perf/perf.c:323 #11 0x4196da in handle_internal_command /home/acme/git/perf-tools-next/tools/perf/perf.c:377 #12 0x4196da in run_argv /home/acme/git/perf-tools-next/tools/perf/perf.c:421 #13 0x4196da in main /home/acme/git/perf-tools-next/tools/perf/perf.c:537 #14 0x7fdf18a4a50f in __libc_start_call_main (/lib64/libc.so.6+0x2750f) Cc: Adrian Hunter Cc: Ian Rogers Cc: Jiri Olsa Cc: Namhyung Kim Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-trace.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 6e73d0e957152d84..b7cbe4bcd136b137 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -1296,6 +1296,19 @@ static struct thread_trace *thread_trace__new(void) return ttrace; } +static void thread_trace__delete(void *pttrace) +{ + struct thread_trace *ttrace = pttrace; + + if (!ttrace) + return; + + intlist__delete(ttrace->syscall_stats); + ttrace->syscall_stats = NULL; + zfree(&ttrace->entry_str); + free(ttrace); +} + static struct thread_trace *thread__trace(struct thread *thread, FILE *fp) { struct thread_trace *ttrace; @@ -1635,6 +1648,8 @@ static int trace__symbols_init(struct trace *trace, struct evlist *evlist) if (trace->host == NULL) return -ENOMEM; + thread__set_priv_destructor(thread_trace__delete); + err = trace_event__register_resolver(trace->host, trace__machine__resolve_kernel_addr); if (err < 0) goto out; From patchwork Wed Jul 19 20:29:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 122818 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2694951vqt; Wed, 19 Jul 2023 13:38:57 -0700 (PDT) X-Google-Smtp-Source: APBJJlFbXJjBGBFdkLoXSUBhj8yWBGB2Ome8funsbI5K20AWK4jozrDcht5HgoSVIUCLUp/ncPP/ X-Received: by 2002:a2e:9088:0:b0:2ad:a78a:df0d with SMTP id l8-20020a2e9088000000b002ada78adf0dmr689224ljg.44.1689799137337; Wed, 19 Jul 2023 13:38:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689799137; cv=none; d=google.com; s=arc-20160816; b=EzfuX176h5wbq3KPBaVm9kB4u7fnJ5uMCTA3hvCudMuJLRiDLEoxcpI+/UanX5uepy a3JzmVl9neVD0WvDn/m5kvvDWH7WLXi26l8pYgQzwzYhKziKcxqkt1eQpixSpGVcfxVn YWugWer2XHezKZiKvpnpu7IbRGnEON+qVkSgRaZ7xgPRFIiQp46+53WDZxg8m3W1FGIo /bVyN7xhqQ7armg7jdmxyG5Cm35BqJuyFPcQpSnRzPOC/tmQDbD0Nnm6aHlztqEbSfhv QZIKnMDatwbNxWFDXNimnFj55hcin6b0iRATOdGf/oYZqvTPHxUcgGiE+Hkp/22x0aXm N5Pg== 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 :dkim-signature; bh=OURjeAMvPNdTXrOz+2tSViWeeLsaiVHSqHL6vKb1WDQ=; fh=ESqlu35PR6uj94JwiiTIyS47HIZcSF+z2GoOs5EJfTc=; b=e/zdP157NqwbwYgOWFW7xN+eKQ1mOWdGTaxmxL4rlPhwQWZRmzhvoDYVG1UKUlQDMW Wyc6KA5/xGf+XJClqxPrN2Fb/bQstv55zXQQO8FiBSud2Tu24H4Ub5feupDKzNj8dVJd QFjARMUFq0DyEcM2xw9HBh+a2XUlUkqLZ15cZqgwZ7NP9WdiiwVVrjRahqe3mYHH4wFm t+TXihN+OooNmISROLf9/xjrla3UHFeld7pcnTX53f85V1RdSaXSPY/+VBL9C/S+1oad eIw8Xp0N++83sVaOr8aYtuq5CMJV+01ySJo1pLBUEKd1z8dYohCjpy0ZVhCCMdvCaFl8 rU+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TtWzTqqI; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pk18-20020a170906d7b200b0098cf3eaee4esi3520616ejb.57.2023.07.19.13.38.33; Wed, 19 Jul 2023 13:38:57 -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=@kernel.org header.s=k20201202 header.b=TtWzTqqI; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230345AbjGSUcW (ORCPT + 99 others); Wed, 19 Jul 2023 16:32:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230416AbjGSUcS (ORCPT ); Wed, 19 Jul 2023 16:32:18 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18AAB1FCE; Wed, 19 Jul 2023 13:31:47 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 44367617EF; Wed, 19 Jul 2023 20:30:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01A12C433C7; Wed, 19 Jul 2023 20:30:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689798611; bh=W5TxjO0FZLzZwTfwZhu1oBz8pm8d9YfgcvKsQLRyIvE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TtWzTqqICusKSGjbNnyVzMjE8Dfl1qMjSh/Xu3oyB41xSqW/4QwcJEQJinP0jRwwl 5Qu272LZfeKTh7+beVG2q7/DL9h6AJlU06B1ijhrpocK0Jio87Mpye9M7n/Pko5S+y Rh2Emq+pWhv48/fy37QIzvp8fanySQByKq/uzphLgMyLzCrAUSt4HCXo6Eg7w9/Cxq jMlVgsRDBIwyKy7YeUB4CtmnznNyrnLu+KgKrLFUA36wAGIScD3Bsmg85wOCC87JC7 Bj8q5lqdIbztrqx1LX3NWGHPaPMilphUNI4lCrvGKuLQGDzcTSrGakZUKsdeUMkkFF xiJ1dVDMq8qGg== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , Kate Carcia , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo , Riccardo Mancini Subject: [PATCH 4/6] perf trace: Really free the evsel->priv area Date: Wed, 19 Jul 2023 17:29:49 -0300 Message-ID: <20230719202951.534582-5-acme@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230719202951.534582-1-acme@kernel.org> References: <20230719202951.534582-1-acme@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771882820272194541 X-GMAIL-MSGID: 1771882820272194541 From: Arnaldo Carvalho de Melo In 3cb4d5e00e037c70 ("perf trace: Free syscall tp fields in evsel->priv") it only was freeing if strcmp(evsel->tp_format->system, "syscalls") returned zero, while the corresponding initialization of evsel->priv was being performed if it was _not_ zero, i.e. if the tp system wasn't 'syscalls'. Just stop looking for that and free it if evsel->priv was set, which should be equivalent. Also use the pre-existing evsel_trace__delete() function. This resolves these leaks, detected with: $ make EXTRA_CFLAGS="-fsanitize=address" BUILD_BPF_SKEL=1 CORESIGHT=1 O=/tmp/build/perf-tools-next -C tools/perf install-bin ================================================================= ==481565==ERROR: LeakSanitizer: detected memory leaks Direct leak of 40 byte(s) in 1 object(s) allocated from: #0 0x7f7343cba097 in calloc (/lib64/libasan.so.8+0xba097) #1 0x987966 in zalloc (/home/acme/bin/perf+0x987966) #2 0x52f9b9 in evsel_trace__new /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:307 #3 0x52f9b9 in evsel__syscall_tp /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:333 #4 0x52f9b9 in evsel__init_raw_syscall_tp /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:458 #5 0x52f9b9 in perf_evsel__raw_syscall_newtp /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:480 #6 0x540e8b in trace__add_syscall_newtp /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:3212 #7 0x540e8b in trace__run /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:3891 #8 0x540e8b in cmd_trace /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:5156 #9 0x5ef262 in run_builtin /home/acme/git/perf-tools-next/tools/perf/perf.c:323 #10 0x4196da in handle_internal_command /home/acme/git/perf-tools-next/tools/perf/perf.c:377 #11 0x4196da in run_argv /home/acme/git/perf-tools-next/tools/perf/perf.c:421 #12 0x4196da in main /home/acme/git/perf-tools-next/tools/perf/perf.c:537 #13 0x7f7342c4a50f in __libc_start_call_main (/lib64/libc.so.6+0x2750f) Direct leak of 40 byte(s) in 1 object(s) allocated from: #0 0x7f7343cba097 in calloc (/lib64/libasan.so.8+0xba097) #1 0x987966 in zalloc (/home/acme/bin/perf+0x987966) #2 0x52f9b9 in evsel_trace__new /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:307 #3 0x52f9b9 in evsel__syscall_tp /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:333 #4 0x52f9b9 in evsel__init_raw_syscall_tp /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:458 #5 0x52f9b9 in perf_evsel__raw_syscall_newtp /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:480 #6 0x540dd1 in trace__add_syscall_newtp /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:3205 #7 0x540dd1 in trace__run /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:3891 #8 0x540dd1 in cmd_trace /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:5156 #9 0x5ef262 in run_builtin /home/acme/git/perf-tools-next/tools/perf/perf.c:323 #10 0x4196da in handle_internal_command /home/acme/git/perf-tools-next/tools/perf/perf.c:377 #11 0x4196da in run_argv /home/acme/git/perf-tools-next/tools/perf/perf.c:421 #12 0x4196da in main /home/acme/git/perf-tools-next/tools/perf/perf.c:537 #13 0x7f7342c4a50f in __libc_start_call_main (/lib64/libc.so.6+0x2750f) SUMMARY: AddressSanitizer: 80 byte(s) leaked in 2 allocation(s). [root@quaco ~]# With this we plug all leaks with "perf trace sleep 1". Fixes: 3cb4d5e00e037c70 ("perf trace: Free syscall tp fields in evsel->priv") Cc: Adrian Hunter Cc: Ian Rogers Cc: Jiri Olsa Cc: Namhyung Kim Cc: Riccardo Mancini Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-trace.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index b7cbe4bcd136b137..56651d666480cc16 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -3151,13 +3151,8 @@ static void evlist__free_syscall_tp_fields(struct evlist *evlist) struct evsel *evsel; evlist__for_each_entry(evlist, evsel) { - struct evsel_trace *et = evsel->priv; - - if (!et || !evsel->tp_format || strcmp(evsel->tp_format->system, "syscalls")) - continue; - - zfree(&et->fmt); - free(et); + evsel_trace__delete(evsel->priv); + evsel->priv = NULL; } } From patchwork Wed Jul 19 20:29:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 122817 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2694821vqt; Wed, 19 Jul 2023 13:38:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlEmMJwislRAz7zHBAA7CENW6/fiTYGmsjQBacYoZbh9qx4qsserptLvEbu6Q2lwbjKmnBtY X-Received: by 2002:a17:906:76d5:b0:992:a618:c3c4 with SMTP id q21-20020a17090676d500b00992a618c3c4mr3732868ejn.66.1689799119538; Wed, 19 Jul 2023 13:38:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689799119; cv=none; d=google.com; s=arc-20160816; b=G+QHU8a8mAPGUPAREip2zMLWTPLC9LzmPk6Q9lMnaO/kaJWprT1wSXHWR3qgyLV1iZ Ju7lAWK7Uzfl97H56Hn3oAeK+PZ2bII/K8efkyaRtiaoq2hS6nfpa9C2q7gHh20L/jrI GxSNhkGGTCUk64Yeh8DgmtHlmrvUWlegJBgjDwl0ekd9bKfN9+Da2RRbvpgB4aHMKat/ snk3GPn5411df2PEUzX6MwRzvYYkXDyHVkraZDt9nNXQ8jTMn/BY6Hv5Mjow9USxz97t sgX6N9wOZ0UbNf68cbTsbJsaXJwT3EkPO4tqNbM+oAjZxHzkR6LV4331++Pkp31WT87Z a+sw== 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 :dkim-signature; bh=el7ECXdGcA5zXIx7KndHyPeorbVHDthOSGMTxMChfXk=; fh=GZ4eSIeu5yUrjQDUyFDhKHpL6itJkKQ8QAaBkaJW/mM=; b=JE9+e7wZdPSWt7+qhwcF6Nz3Dz7+yj4twnpcir/4WmefJAMz6p7vdcCNgCel+B2MnK npxn5o++5Xw1c4ox2oBFajbc9fskx/rWBhSv+QvOzMo+jZsDAJvl/PdGzv9wbE2RxevM B0R13FKYfr9ajXgvWUoCCfJN3sjud+ni/KVhhhH2fmUixwW5UT+66aKmwnLkC1BoLLVB wpP1/6wcY1ouRKxNv5hvwm9LGBmnLDwwygF7EAjzTlOVoz/0ko2yvmGf6cS6uuoL6XNC a/yXYeOUP27fPx2AppLN0qw8jibOximuZveuziIL2oYx2HLcLaINZoEyo5ZTV+9OO9z4 9i/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pOpuhOAI; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gy21-20020a170906f25500b009903666fcd0si3121640ejb.384.2023.07.19.13.38.15; Wed, 19 Jul 2023 13:38:39 -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=@kernel.org header.s=k20201202 header.b=pOpuhOAI; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229926AbjGSUb6 (ORCPT + 99 others); Wed, 19 Jul 2023 16:31:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230500AbjGSUbw (ORCPT ); Wed, 19 Jul 2023 16:31:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26F531FFE; Wed, 19 Jul 2023 13:31:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 414716182C; Wed, 19 Jul 2023 20:30:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 29EE3C433C9; Wed, 19 Jul 2023 20:30:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689798614; bh=Na90jgwrhK74RAguQcWtc6XkFOL8jLuOvNfJ2Q5L1OY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pOpuhOAIG0e+iG62LTVp/tOhm8LzD0rRM3ibmk6yVo2hwFY4DhRRdPheSDbNtDfLM Bujg66J+7JICkSoBp8HPkMxK8Oz9qAIFFYgSA48TfTO622vnYlLwyj94nmtCQjaERL Ki6o1XPdvRhWJuJQU8gNFU0gqxGmVDi3SzDaz3L/MQaIMtVkdSZEDayVa9x6f6OI5P F42+Gsb7vi1AnoIObXd2JQ3OR/PYcLPk+k8Tza/Q2VAXpxFNEYZWUwKP32kqJJrqe/ BygHJnfOXWU0sQOHnWoByHfFO0TcbocwzUBIZVgP0CDKQ+1Eu7ro2EbL12/yP7SYXU QLyVqMMsrD/tw== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , Kate Carcia , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo Subject: [PATCH 5/6] perf trace: Free thread_trace->files table Date: Wed, 19 Jul 2023 17:29:50 -0300 Message-ID: <20230719202951.534582-6-acme@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230719202951.534582-1-acme@kernel.org> References: <20230719202951.534582-1-acme@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771882801727665275 X-GMAIL-MSGID: 1771882801727665275 From: Arnaldo Carvalho de Melo The fd->pathname table that is kept in 'struct thread_trace' and thus in thread->priv must be freed when a thread is deleted. This was also detected using -fsanitize=address. Cc: Adrian Hunter Cc: Ian Rogers Cc: Jiri Olsa Cc: Namhyung Kim Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-trace.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 56651d666480cc16..7ece2521efb69182 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -1296,6 +1296,8 @@ static struct thread_trace *thread_trace__new(void) return ttrace; } +static void thread_trace__free_files(struct thread_trace *ttrace); + static void thread_trace__delete(void *pttrace) { struct thread_trace *ttrace = pttrace; @@ -1305,6 +1307,7 @@ static void thread_trace__delete(void *pttrace) intlist__delete(ttrace->syscall_stats); ttrace->syscall_stats = NULL; + thread_trace__free_files(ttrace); zfree(&ttrace->entry_str); free(ttrace); } @@ -1346,6 +1349,17 @@ void syscall_arg__set_ret_scnprintf(struct syscall_arg *arg, static const size_t trace__entry_str_size = 2048; +static void thread_trace__free_files(struct thread_trace *ttrace) +{ + for (int i = 0; i < ttrace->files.max; ++i) { + struct file *file = ttrace->files.table + i; + zfree(&file->pathname); + } + + zfree(&ttrace->files.table); + ttrace->files.max = -1; +} + static struct file *thread_trace__files_entry(struct thread_trace *ttrace, int fd) { if (fd < 0) From patchwork Wed Jul 19 20:29:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 122823 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2699621vqt; Wed, 19 Jul 2023 13:49:17 -0700 (PDT) X-Google-Smtp-Source: APBJJlFVbCxe72zwDP58BMSU0dQqL14ps+nf4MKgtvyIyFCbKXa37oh0MNPV4FZ/e6la7VtJFCfN X-Received: by 2002:a05:6a00:4888:b0:666:6c01:2e9e with SMTP id dk8-20020a056a00488800b006666c012e9emr4242775pfb.15.1689799757327; Wed, 19 Jul 2023 13:49:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689799757; cv=none; d=google.com; s=arc-20160816; b=Sd833j9pdN6aUzulp9m6/IZn5sYtaKe85uPljbmUeJDLATTtjoR/AKdttuNzYgh5Vk dNKIMe9E/0YY61g+FOi6mI/DuKl0hRPWkGNNxf+9qjk8x8ezOBSmybkpFt7jPyiZm0y8 m52zUxWxScfhjMEXMMjv3P2Dvi9cSBm/SF0FsZy3I2R9XCDpzO848B6X2kDnu+RSstbT +QXEsCAvksR/3i2mm8fgrcGr2HbYgTq47xVYWVlOhgrIaxp1pDMfKnM5ZhumPL3lN+es qp68auwLQlyCP14aBfv85YcYQmo8wy8GLs1nsvojUPOi0CPQTsVozFwollMKjqMrhVMk GADA== 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 :dkim-signature; bh=Vw9oMKjj8bxSlXKEWqNNiNX0ehTMSKb9Ty3CPBneJmk=; fh=4p9qXw0C2eeKBm3REnGOum18kCoVTpV/Vo5A3QJGdeU=; b=DJBy73ltnt8AscHxDYLAV5fnzSH7YXdB09wrF194Z2N4PA1le9AUIvNHoXU1a5E50R 5EORe1SkkoMjQJhvh3J9x9+aljkBiUEtiL+W4jIZKxTpuUwiizHih2N4x9cBt+V5LUI2 SQNtwie+b39M9S1Om05+kyHJOswUsXvLroWh00yIWjWv9WJRWAcV6sQEAg+M1MQm2XKa s1uUUWc/6pTw0/bHKviyUhw4dekZC9pg/W6O4BzqCwjV/b5z+T+9bKsXfSVl3mcKmsQK RWRq9SKUvD+yHGU9w+CJWQuvbKaasRl9pFLVX2cxCwn6g06M+1MvNtz9Lg3yJHsjARyh e9fA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=axJJJjho; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cw4-20020a056a00450400b0068208d19b1dsi4034095pfb.153.2023.07.19.13.49.03; Wed, 19 Jul 2023 13:49:17 -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=@kernel.org header.s=k20201202 header.b=axJJJjho; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229790AbjGSUbw (ORCPT + 99 others); Wed, 19 Jul 2023 16:31:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230117AbjGSUbn (ORCPT ); Wed, 19 Jul 2023 16:31:43 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A99D26B5; Wed, 19 Jul 2023 13:31:16 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2C8DD61839; Wed, 19 Jul 2023 20:30:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 271EFC433C8; Wed, 19 Jul 2023 20:30:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689798618; bh=1vKuor530DqdUWvj3A6ZHk0xp319J5oxWV8iIp7ZRbE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=axJJJjhoB1d/V6B78nfcClFeFzN+j9vXDmKWCJzen95hI+swQxVX+VdaG0a2O5c4s nlF0uxBUP4V1KrZgcZz4NCyx3WIVUugAkbvepB993BYq4HXagq141aYuXdZnDg4JhF +GEptC79VWgkDYJh+XZLfNQUbm7OeVL89Klo/SimsXdf9Cy8NyecwWphk6Q2EZOAti vhWwRIa9JNrSe23rEwvvQwXUUicOaHoim+QxujoLdBPxZIqWr3FXriRGAqjdTPci/U 1cjsOq8gawDrT8WdQWEYfmyIIwRexQqgUHPIXXuSLRozVXmobJ4sFetz8w6YOSKtci HHQekA+dmgvDA== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , Kate Carcia , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo , John Garry , Alexander Shishkin , Ingo Molnar , Mark Rutland , Peter Zijlstra Subject: [PATCH 6/6] MAINTAINERS: Add git information for perf-tools and perf-tools-next trees/branches Date: Wed, 19 Jul 2023 17:29:51 -0300 Message-ID: <20230719202951.534582-7-acme@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230719202951.534582-1-acme@kernel.org> References: <20230719202951.534582-1-acme@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771883470036784310 X-GMAIL-MSGID: 1771883470036784310 From: Arnaldo Carvalho de Melo Now the perf tools development is done on these trees/branches: git://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools.git perf-tools git git://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git perf-tools-next For a while I'll continue mirroring what is these to the same branches in my git tree. Suggested-by: John Garry Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Ian Rogers Cc: Ingo Molnar Cc: Jiri Olsa Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Link: https://lore.kernel.org/lkml/CAP-5=fVGOP6-k=BTRd_bn=N0HVy+1ShpdW5rk5ND0ZGhm_fQkg@mail.gmail.com Signed-off-by: Arnaldo Carvalho de Melo --- MAINTAINERS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index aee340630ecaea38..e351cfc7cd41c570 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -16629,6 +16629,8 @@ L: linux-kernel@vger.kernel.org S: Supported W: https://perf.wiki.kernel.org/ T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git perf/core +T: git git://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools.git perf-tools +T: git git://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git perf-tools-next F: arch/*/events/* F: arch/*/events/*/* F: arch/*/include/asm/perf_event.h