From patchwork Thu Apr 27 23:05:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 88402 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp584509vqo; Thu, 27 Apr 2023 16:16:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4sVH6R8ZtWSKv+KE4f0trYT+Fvbeqe6TCgMPMkc1H/ku3iuYh1ZvqPiSgHJVs9B1hL9LO2 X-Received: by 2002:a05:6a20:72a7:b0:f0:662b:337 with SMTP id o39-20020a056a2072a700b000f0662b0337mr4129445pzk.60.1682637379013; Thu, 27 Apr 2023 16:16:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682637378; cv=none; d=google.com; s=arc-20160816; b=Ssr1M4suz8DrdX0P/gqr3hylN5IcP1i1XnGE123UV0mORRolmp/ibWrCpoP+AhAI4v XRszGOn/CcDDk7SFN65KLMojr7/o0kTyqF+FdIvReMu9/wYOdMERAs28HX5n7uskJoaB XPiMD6hxSGZdBdr9u5visIQaktxokmdi4Hhq6i0xynGKxe5ERLFPjrUUbup5uAYhZBZE dsY0Nakiuc3GZApUygUJS1F8FIKD494uiuxrELq+Eb8yxqf9gcjMeLByZ/We0uVg1xBA gjKYPDIIKh/BDa63wNI1u/EgiknX3ZvJSrMuww9fO/3cCtFE6PKXGodNFvrVD9VFPiwM V5QQ== 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 :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=SuthzOP7teE2TJtcGVgcOBqXsLnkwl8x+Mo6/AZ4cCs=; b=mj3P1iYUxPCn66IEFcVZ88d/3L939o7OCUTTKtSU1sVK+/5i3Asw07pnPR7RDy8KiX YLcsLKIagc9SFi9+B1oHlmW3uh4ttt5PAvP2cBJvKo2qA3OIL6MWeSYEHtoDqiGU1VJk e69zp6VWuAICWi8zH5zMVamWHPEi0mZyjy2o542h4ajddYV73i5WuzGXXud15QBaH678 5vXigscQZDVAaM9IQ4q3uZYlwyKkmM2ihSGqkabiM85592lW10ecu+F6QA3F38njnLvc 4cyEkn2/GqqQgM6ZluvU2xA0Y/RUGn7nyvbfGNY8Qs/3nnofdkI+5f+nPqciOWqNaqe2 7log== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=aoJq6G8C; 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 q17-20020a63e211000000b005250c24fa2dsi12814530pgh.293.2023.04.27.16.16.04; Thu, 27 Apr 2023 16:16:18 -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=@gmail.com header.s=20221208 header.b=aoJq6G8C; 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 S1344375AbjD0XFJ (ORCPT + 99 others); Thu, 27 Apr 2023 19:05:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229783AbjD0XFI (ORCPT ); Thu, 27 Apr 2023 19:05:08 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F32FC2D65; Thu, 27 Apr 2023 16:05:06 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-63b7096e2e4so7539452b3a.2; Thu, 27 Apr 2023 16:05:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682636706; x=1685228706; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:from:to:cc:subject:date:message-id:reply-to; bh=SuthzOP7teE2TJtcGVgcOBqXsLnkwl8x+Mo6/AZ4cCs=; b=aoJq6G8Cs2aJyA2rh6thgp9O9iK7mqRD4ejT5mN1yHmdQFwQCQLq0uUgCMF1mfyGXw I/jLLuAb//ODC2yli2oQOQyOhByc79nrXhPmvehX/1+Igw1QCSQ2FQHZGOydR4IDUY1B q72u27YbAnnx7Khav2KLXm5i86BfDJ2m3vxzx+LJHbL8L4emVkamcDa4HcT/zLWGZ6vW V2BBi7Mx3BYBck4Jn1paG+lzFBWbh81bzMpioyLriARqt66QdbDKPWZlMoTOFowsr4hZ 493JPsIzCKZA/LC+qbwL0QGVAQvZEYbo+JzRKElKN4sz7ABuyC/U8470vh+0uKwpQdoR /JGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682636706; x=1685228706; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=SuthzOP7teE2TJtcGVgcOBqXsLnkwl8x+Mo6/AZ4cCs=; b=dfOvVdS7IQTTLpqNLy3F3yE+8pevJg4i3R5Dw9pJGYvFgz1u1xvhdQgbHRHw34UOwW S3TQSAfspB86089yVoZv89t7UZy7RJuF5aHq+9lJ1TPO2VXhDLfMyz+kQEFL59C1Va6m jSZ0oWTwOcijd466XQF/UFMB+JPYEMq0eeM+JzO8e22Xs34Bd25VhxX4Ic6ZHx1Mt4P8 zagNYON9IucHrDV2dhipklm0OeiMrNcIWM9KWlfcvFz5vHS2cHQ93GhuWrbSARH6FZXg E/YuHuisHB7VrpaTUg+h4mFo6BwogS2/66O9P/wXgB+F0xYBJ5MGFScC7tnUmtZTuEmj 4Azw== X-Gm-Message-State: AC+VfDyQpHeVCmZAszdkjDxajbjGJCJ4O7RiL7un4EDeWTlZYuLLsa7p y1f6sln7jlArdroIOREps6g= X-Received: by 2002:a05:6a20:3d84:b0:f5:3f3e:b716 with SMTP id s4-20020a056a203d8400b000f53f3eb716mr4044876pzi.28.1682636705649; Thu, 27 Apr 2023 16:05:05 -0700 (PDT) Received: from moohyul.svl.corp.google.com ([2620:15c:2d4:203:55cd:594d:edb:e780]) by smtp.gmail.com with ESMTPSA id p10-20020aa79e8a000000b005d22639b577sm13636436pfq.165.2023.04.27.16.05.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 16:05:05 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH 1/2] perf list: Fix memory leaks in print_tracepoint_events() Date: Thu, 27 Apr 2023 16:05:01 -0700 Message-ID: <20230427230502.1526136-1-namhyung@kernel.org> X-Mailer: git-send-email 2.40.1.495.gc816e09b53d-goog MIME-Version: 1.0 X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764373172204711726?= X-GMAIL-MSGID: =?utf-8?q?1764373172204711726?= It should free entries (not only the array) filled by scandirat() after use. Signed-off-by: Namhyung Kim Reviewed-by: Ian Rogers --- tools/perf/util/print-events.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c index d416c5484cd5..0a97912fd894 100644 --- a/tools/perf/util/print-events.c +++ b/tools/perf/util/print-events.c @@ -83,11 +83,11 @@ void print_tracepoint_events(const struct print_callbacks *print_cb __maybe_unus if (sys_dirent->d_type != DT_DIR || !strcmp(sys_dirent->d_name, ".") || !strcmp(sys_dirent->d_name, "..")) - continue; + goto next_sys; dir_fd = openat(events_fd, sys_dirent->d_name, O_PATH); if (dir_fd < 0) - continue; + goto next_sys; evt_items = scandirat(events_fd, sys_dirent->d_name, &evt_namelist, NULL, alphasort); for (int j = 0; j < evt_items; j++) { @@ -98,12 +98,12 @@ void print_tracepoint_events(const struct print_callbacks *print_cb __maybe_unus if (evt_dirent->d_type != DT_DIR || !strcmp(evt_dirent->d_name, ".") || !strcmp(evt_dirent->d_name, "..")) - continue; + goto next_evt; snprintf(evt_path, sizeof(evt_path), "%s/id", evt_dirent->d_name); evt_fd = openat(dir_fd, evt_path, O_RDONLY); if (evt_fd < 0) - continue; + goto next_evt; close(evt_fd); snprintf(evt_path, MAXPATHLEN, "%s:%s", @@ -119,9 +119,13 @@ void print_tracepoint_events(const struct print_callbacks *print_cb __maybe_unus /*desc=*/NULL, /*long_desc=*/NULL, /*encoding_desc=*/NULL); +next_evt: + free(evt_namelist[j]); } close(dir_fd); free(evt_namelist); +next_sys: + free(sys_namelist[i]); } free(sys_namelist); From patchwork Thu Apr 27 23:05:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 88404 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp590065vqo; Thu, 27 Apr 2023 16:31:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7oKdHcUKxdMzkNSCOWBI/MP3ZCCy8umqC5SrwE3A7nhxFkvH6c2XJPHhzBYDJWSe0De01x X-Received: by 2002:a17:90b:18e:b0:247:6022:9595 with SMTP id t14-20020a17090b018e00b0024760229595mr3280722pjs.45.1682638284832; Thu, 27 Apr 2023 16:31:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682638284; cv=none; d=google.com; s=arc-20160816; b=afa3Kbl2DA6/DcdL/CH749507N+mORc7pGC9KeaLuY0ZxMVG965Xoa3TkGhTTm5P/r HWqTTDnVEEtqDLaJ1vaXIeSN1r/4r3rAiBZnLsGmTI/VF7KtauRYvyW3NB8pSpvmtWx9 7vjmDtx6fKBdTPS+5L265yFyEjyN1ilRTUghWizJ06pro7X+Uq3PeAI4abxNzyBLP/Ls Z0OXviNg2PoIK92WM18r1FGdG0BUp0K0mrfxJMQQNqSAvysUQvrVHQEqCfGhEEJpOJ6K cown8KFtpQnYsb/HTkVGIMzRCQBMj1EoBD+2CcgigHVHjBxrZo/E7+fpAED0QgF07Btk RCSQ== 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:sender :dkim-signature; bh=In1jC5aMTJeXFFu1GOLM89hDF8A0gRuTYGTK8R3GUQA=; b=RSihr61qfIHCjvZdDwQsC5tCUp67l1EvcPJ59VxzVmmh9vEOO3ntidK4wn1Z3fiEwe ZYkqYMXz/V2s/5HLssFyYLlpiWaegGcLVw7a1EzHMCIHPKSBMu7nikIhj1LL8J0cSpi1 hFli9+3moKIsc0zaoNANJUVavm7cqH6VRsxQpynqC4o/jni9K/D5NAgtR3OKzlQDsyyz XsYnhbPEfhFdmpqd3k9fLxL9m417n0noVVo6FJFkoEn6op7Bx7Q8ifuOU0REKG3KdjvB 3vyTpCyn8r714qXYAC8GIs27YgtHCqMbc0k0S1aVagtUoiOVdy8eunVkQ0cWQV00lAUa tg9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=kb13oXou; 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 d6-20020a170903230600b0019ceaf40d5esi18106123plh.107.2023.04.27.16.31.09; Thu, 27 Apr 2023 16:31:24 -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=@gmail.com header.s=20221208 header.b=kb13oXou; 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 S1344382AbjD0XFL (ORCPT + 99 others); Thu, 27 Apr 2023 19:05:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344175AbjD0XFI (ORCPT ); Thu, 27 Apr 2023 19:05:08 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75C582D40; Thu, 27 Apr 2023 16:05:07 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-63b78b344d5so7137951b3a.1; Thu, 27 Apr 2023 16:05:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682636707; x=1685228707; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=In1jC5aMTJeXFFu1GOLM89hDF8A0gRuTYGTK8R3GUQA=; b=kb13oXouVsalgzAXfCrJ9C6LOHHlMnB3wIIENBte3E7lIOvdo1M1rdAI8s4Kusqy2K 1Fal7nzjG9zElqXMAHVZbGahhQqXQ2IHZVAOuS65/meoHEojml+TKuugjQiMJ4L3YM3P J4W5s00Idg4JFlUWwzCgrMJ0Kxx9Jn20Tko6sxORno1jaRPjClIjua2Kgl64bbCeyCY6 L3T3TpJvGYlMTuqVGiFIClH/V8vuMTo9i94UKAnhWtwP2b+gY4L6pmwrMrknSPfNSAef XRzMKL5Z4JkO4cANNdMPXvPtgWcRGUpemwgj1V2CI0Ye/ULEQR/DkCd/HkyJP+HvxW2A Lf3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682636707; x=1685228707; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=In1jC5aMTJeXFFu1GOLM89hDF8A0gRuTYGTK8R3GUQA=; b=hb6Fvw0ULtQTG+XBSN76DEWeXPKlM19pBMAN50TrhS1gAya5Z4R0KYS9RYZLXYhR3d Zoafu9irh354vtVTr3msaVSEte3O2ywgTPThR/2odeMDzc2CFjSZLOPBDTLf0uO9omiL iLv4A7DhENDNPluipQg+z5bObbBi77RJsKFtw5jO3uoHnl/4QSmgsK9OG6lNgKqB+3rz SW7HIHGNAEmgihpdZu6O6URJ4+0SiASXMXpzTFs/HTUpKcRu8RmYGudVRSy7sgJlNx/W eoGfAZ5vEcsrqlyElTSeUcz9iuYcDODjCTOJid6vgafIHdlHrTvZmE5k6Wihp0WiJ3Si Boew== X-Gm-Message-State: AC+VfDxDRCq8jre6dHUhi7uZSp0UIhnBsrdobPCcIMKV/qaQrb6w285t 3o8gbDHJvLWXrU4+1yTJIdM= X-Received: by 2002:a05:6a21:78d:b0:f1:377a:b762 with SMTP id mg13-20020a056a21078d00b000f1377ab762mr3380293pzb.33.1682636706789; Thu, 27 Apr 2023 16:05:06 -0700 (PDT) Received: from moohyul.svl.corp.google.com ([2620:15c:2d4:203:55cd:594d:edb:e780]) by smtp.gmail.com with ESMTPSA id p10-20020aa79e8a000000b005d22639b577sm13636436pfq.165.2023.04.27.16.05.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 16:05:06 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH 2/2] perf list: Modify the warning message about scandirat(3) Date: Thu, 27 Apr 2023 16:05:02 -0700 Message-ID: <20230427230502.1526136-2-namhyung@kernel.org> X-Mailer: git-send-email 2.40.1.495.gc816e09b53d-goog In-Reply-To: <20230427230502.1526136-1-namhyung@kernel.org> References: <20230427230502.1526136-1-namhyung@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764374122330690749?= X-GMAIL-MSGID: =?utf-8?q?1764374122330690749?= It should mention scandirat() instead of scandir(). Signed-off-by: Namhyung Kim Acked-by: Ian Rogers --- tools/perf/util/print-events.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c index 0a97912fd894..299973876550 100644 --- a/tools/perf/util/print-events.c +++ b/tools/perf/util/print-events.c @@ -131,7 +131,7 @@ void print_tracepoint_events(const struct print_callbacks *print_cb __maybe_unus free(sys_namelist); } #else - printf("\nWARNING: Your libc doesn't have the scandir function, please ask its maintainers to implement it.\n" + printf("\nWARNING: Your libc doesn't have the scandirat function, please ask its maintainers to implement it.\n" " As a rough fallback, please do 'ls %s' to see the available tracepoint events.\n", events_path); #endif close(events_fd);