Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp544477pxv; Thu, 15 Jul 2021 09:55:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwAwHfVEE1qFMrPLO1rw3mLkrBV0y4ggPHsA2D69GqbPVHt8OozGWq8ttSrbtS2T99GKmSW X-Received: by 2002:a50:c88b:: with SMTP id d11mr8610138edh.318.1626368120611; Thu, 15 Jul 2021 09:55:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626368120; cv=none; d=google.com; s=arc-20160816; b=O87cSXBkJq9ydwYOuDVmehpWDDC8S9vR6QjEC9DfxgN1hjDzY4+RwIGfwj02qlTydL pRoBvPa1vKH2Z45+U/LvtKU4opwwBLwdAIfKYup0dg4tvuqsrRTAiwbLmPHpQfbYHqjf GcZ+Ka+XYSthXSSmA/hQMsGXGjde/bDn2+6gkTuRhwQLnEew39m0Kh6Q8f0Q5tKKduN4 WyFt6LoJGFQNvJP4Uh/nJ1tXVtYEqou0USHoeQqxgJxRuFKAZQWJxsHYz9STOBfB3Hkd b85jQbANtl9NF1dxRKdrgZBxZ5Ayzh2M42HNKhN3LmC2+m4zQdroVMil7qO4ae7RAGmp yaQQ== 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:dkim-signature; bh=OGn8v0AZsNXonIn+TnzTtj2wqzovhDsmhmy5/5DhM/8=; b=L65OsVqghzAS2OUY30Kk8qEjvfrMnLCcrhsXzRuQkYT8Y/xU1pxsy4tl1+t1ihhXEI OkT+f4mMNAbZWJztESdcHoegUl3lU6ob9JrursrMqB7ucsYC9atZxuiorDP0VTg9h3lc 1nc1Inc0rQYrHkPGCDaej+FnGzsUz0i/Ek5wvKzklWsnQGFKgWY1euSqP8lXljOxgDm/ VdDDaccaA4grFN2AIdqxFdKygnhcQYYa7JXKiOLtPupFgMz5/8D1N2oGPxRDi8364fVG PMgSp9igVZo3y4k5yuVjgTZ6ijiPAx4yI3uIrd1SOF5MJnWok4a7+PVUVw4zF3kOUvHn NipQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=OeZpCvis; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ds7si9522392ejc.304.2021.07.15.09.54.58; Thu, 15 Jul 2021 09:55:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=OeZpCvis; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230296AbhGOQKW (ORCPT + 99 others); Thu, 15 Jul 2021 12:10:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229531AbhGOQKW (ORCPT ); Thu, 15 Jul 2021 12:10:22 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0EE4C06175F; Thu, 15 Jul 2021 09:07:28 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id r11so8462587wro.9; Thu, 15 Jul 2021 09:07:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=OGn8v0AZsNXonIn+TnzTtj2wqzovhDsmhmy5/5DhM/8=; b=OeZpCvisTOhnd71MPRLK0V7gZDYoqiNFQurDLT8k2K34SOombDHvrPaaSAxloaJ16l DiNzKrzpVsMJHFnvRSBuyggyHXZw9VR+0U1BeBgMkb/om92Hogu1wc4v6LK2EJd83MQ6 2zYsD3DmOsa3H7TbyUijriLOoLX42T4nWubRT+V5qS7bueHf0xIQd31P/UmP1g7Xhtgi 1JrAuVtd0m5VUo1KS8OQI5Jp2Xfge9wpJQp9VrVbkX05cwg3LxykW61gZptDdicGnc9Q Mcm6G+1XH0+amZx+JIEfReNVgqYnwJvl5A5fFhX/gSitDhALVXiwvHrRqvk74uWKaoTh R/RQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=OGn8v0AZsNXonIn+TnzTtj2wqzovhDsmhmy5/5DhM/8=; b=syTZWs1xXxnJ/Zr3G4N47PnL4ymAotvtGnArsZu2XrOrNNsZS33n8waElgXBLmycwQ yVNU/3Atv+6kM7kFHF+/+ezEoABGXnsZs2LRBYAEhPbwOg/OlgciP1Z8yB5LbsUBmwOu h65ZzMsDbBhirNkxrNxskxHA8iGZXUztWM7DBDLk7h806IJj+VK+msgxqRYt15d1zGv+ jOWbXp6+nE8voY1I6GArF9/CGU6HJvw0VG4gewwiM/ErSHtodA0qlsE8GJKCQmORZfPX 8Bk4+hyLtMTVk2ucUOTVwNaqTjqQ/VwOgbbnp0SXntIlIQINrjv44lAFAynxf0pvxgDe Xr+Q== X-Gm-Message-State: AOAM532cJmjll2dFngqgiTd0l/2h6pPB9/SodwfwBq3vkHRBWTqwGre/ rJbAgX0xpT+aM/A5Ky0Z19U= X-Received: by 2002:adf:f149:: with SMTP id y9mr6402880wro.85.1626365247085; Thu, 15 Jul 2021 09:07:27 -0700 (PDT) Received: from honeypot.lan ([2001:b07:6456:fd99:ced0:db1c:53e1:191e]) by smtp.googlemail.com with ESMTPSA id k13sm7446952wrp.34.2021.07.15.09.07.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jul 2021 09:07:26 -0700 (PDT) From: Riccardo Mancini To: Arnaldo Carvalho de Melo Cc: Ian Rogers , Namhyung Kim , Peter Zijlstra , Ingo Molnar , Mark Rutland , Jiri Olsa , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Riccardo Mancini Subject: [PATCH 00/20] perf: fix several memory leaks reported by ASan on perf-test Date: Thu, 15 Jul 2021 18:07:05 +0200 Message-Id: X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patchset fixes several memory leaks found using ASan on perf-test. After this patch, all memory leaks in perf-test that were found on my machine are fixed. This does not mean that there are no longer memory leaks in perf (just running perf report or perf top raises a few), but that now it is possible to run the perf tests with ASan to catch future memory errors. While many of these leaks have little to no effect on the daily use of perf (some were inside the test itself, other were just a missing cleanup on exit), other were (slightly) more serious, namely: - nsinfo refcounting was broken since it was not decreased when a reference was replaced, causing many nsinfos to never being deallocated. - dso__new_map refcounting was wrong, missing a __put - lzma stream was never closed Below are the results of perf-test before and after this patchset. Only failed and skipped tests are reported for brevity. The perf binary has been compiled using make DEBUG=1 EXTRA_CFLAGS='-fno-omit-frame-pointer -fsanitize=address' compilation using clang shows same results. Tests are run on my laptop: Intel(R) Core(TM) i7-5500U CPU @ 2.40GHz (2 cores + hyperthreading) Fedora 34 w/ kernel 5.12.14-300.fc34.x86_64 Before this patchset: 1: vmlinux symtab matches kallsyms : FAILED! 19: 'import perf' in python : FAILED! 23.1: Read Only Watchpoint : Skip (missing hardware support) 31: Lookup mmap thread : FAILED! 41: Session topology : FAILED! 42.1: Basic BPF filtering : FAILED! 42.2: BPF pinning : Skip 42.3: BPF prologue generation : Skip 49: Synthesize attr update : FAILED! 58: builtin clang support : Skip (not compiled in) 63: Test libpfm4 support : Skip (not compiled in) 65: maps__merge_in : FAILED! 73: DWARF unwind : FAILED! 78: build id cache operations : FAILED! 82: Use vfs_getname probe to get syscall args filenames : FAILED! 83: Zstd perf.data compression/decompression : FAILED! 86: perf stat --bpf-counters test : Skip 87: Check Arm CoreSight trace data recording and synthesized samples: Skip 88: Check open filename arg using perf trace + vfs_getname : FAILED! After this patchset: 19: 'import perf' in python : FAILED! 23.1: Read Only Watchpoint : Skip (missing hardware support) 58: builtin clang support : Skip (not compiled in) 63: Test libpfm4 support : Skip (not compiled in) 73: DWARF unwind : FAILED! 86: perf stat --bpf-counters test : Skip 87: Check Arm CoreSight trace data recording and synthesized samples: Skip After this patchset, without ASan: 23.1: Read Only Watchpoint : Skip (missing hardware support) 58: builtin clang support : Skip (not compiled in) 63: Test libpfm4 support : Skip (not compiled in) 86: perf stat --bpf-counters test : Skip 87: Check Arm CoreSight trace data recording and synthesized samples: Skip The two failing tests are false positives and can be skipped: - "19: 'import perf' in python" fails since there are memory leaks inside the python library. - "73: DWARF unwind" fails due to stack buffer underflow, since it's unwinding the stack. Riccardo Riccardo Mancini (20): perf nsinfo: fix refcounting perf env: fix sibling_dies memory leak perf test: session_topology: delete session->evlist perf test: event_update: fix memory leak of evlist perf test: event_update: fix memory leak of unit perf dso: fix memory leak in dso__new_map perf test: maps__merge_in: fix memory leak of maps perf env: fix memory leak of cpu_pmu_caps perf report: free generated help strings for sort option perf inject: close inject.output perf session: cleanup trace_event perf script: release zstd data perf script: fix memory leaks in perf_script perf util/lzma: close lzma stream perf trace: free malloc'd trace fields on exit perf trace: free syscall->arg_fmt perf trace: free syscall tp fields in evsel->priv perf trace: free strings in trace__parse_events_option perf test: bpf: free obj_buf perf util/probe-file: delete namelist on error in del_events tools/perf/builtin-inject.c | 13 ++++++--- tools/perf/builtin-report.c | 33 ++++++++++++++------- tools/perf/builtin-script.c | 8 ++++++ tools/perf/builtin-trace.c | 51 +++++++++++++++++++++++++++++++-- tools/perf/tests/bpf.c | 1 + tools/perf/tests/event_update.c | 6 ++-- tools/perf/tests/maps.c | 2 ++ tools/perf/tests/topology.c | 1 + tools/perf/util/dso.c | 4 ++- tools/perf/util/env.c | 2 ++ tools/perf/util/lzma.c | 8 ++++-- tools/perf/util/map.c | 2 ++ tools/perf/util/probe-event.c | 4 ++- tools/perf/util/probe-file.c | 4 +-- tools/perf/util/session.c | 1 + tools/perf/util/sort.c | 2 +- tools/perf/util/sort.h | 2 +- 17 files changed, 116 insertions(+), 28 deletions(-) -- 2.31.1