From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.200 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796524475; b=i/ts8GwwuWofr5oe+RXwOcitlEYBd41fI4mjF3EglW31r0NKReg06xdYK1tIjfWGQl5J t0xBlHriv4W7TdF9ePHl64q9w+AfxP67DCc+E1tDJROpnHtT43NVIkNzUcmoBjKzfMKsN Ei1hS4pmzqpljnl606DKxma4GxIMe41xrRbVQCcG2dvmTt94dNIW21hGDWgq4tYup0Hku NO0Bmmk6dOqxxDu9VcrGzNoP15iCxY3wMe1h4/Si1bXDLnp6PXLyT8X1Kw5zkJROGKoyJ u4fjsDOIoQSMJHniqHCEwdPnYr6Bt/hJnjHjEuzFeivs/F8+R6gr1+FtwxM2Sl8qTqg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796524475; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Received:Date:In-Reply-To:Mime-Version: References:X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=ABXlZSN9FvIxEM3kJZW0lAJm3Jov8qSy58r/YUWoR3U=; b=FzL4Z5/PGcNLXTWjgLu5uHCMEX0VKQMG9NdOABOqjFVw7AHNbhsCK+DCZ3qkTdOKFnck zRuFCVTQ2Tjn4K21kagEoaPxTCv98X19gIMNqSc9Iptgyc6hYR/8qguI54Uf6r8IB8zJK Yhtzh0AXcyBBFat9NIfLPq7YyCYEHJyhUh+N0CsCtNrPUYr9iAzHK7K8UzC2dwimWK9Kx Wu5EQJxlzYGAQbeabIed/jdUaKITrm+5GIfYQ4Jqci6DPZ/MhETyNQm4WTA2ZHQyZDhvY FG1jiFBs6mMInUtXLD53m7a+Sv4BfIx7uPRoV2VyljjbJR+ZE/r9woil/H5d4f4NZSA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=EWn69cLq; arc=none smtp.remote-ip=74.125.82.200 Received: from mail-dy1-f200.google.com (mail-dy1-f200.google.com [74.125.82.200]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 05E55606A330 for ; Sun, 6 Dec 2026 02:34:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 05E55606A330 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=EWn69cLq Received: by mail-dy1-f200.google.com with SMTP id 5a478bee46e88-30bcb065bfdso2970198eec.0 for ; Sat, 05 Dec 2026 18:34:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796524474; x=1797129274; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ABXlZSN9FvIxEM3kJZW0lAJm3Jov8qSy58r/YUWoR3U=; b=EWn69cLqinIoucvRwvixnQzQMfTk/C6GjelPw+30cMyIFQu4Wb1uHAoRfmD59Ksp8o /Dz68uw1hzmQiQwV9/sAa+sIxTTogdNMmDZ8AuSh/ZoeemljENo1CMnWDAIQgmxM5ERQ E9sh1FOiJMSO3+xAVYjm8O6IVsYyfhiL0ul/NqdzFy7Xgjfxoe1q9WU5XNxzDaiilBef nvIyjLAA/9M8rgWjS6rJ1vg60BvjW5jCcE4WomPmPAYMHCst4UEyQrfppl+BMGUwYpQT eKY3yf3SdPdP8piYfLoNfvjq74WKIndU50A+2pqqk65/8jDmmB6xxSjj5XZXH42aBMGl zx5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796524474; x=1797129274; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ABXlZSN9FvIxEM3kJZW0lAJm3Jov8qSy58r/YUWoR3U=; b=xp/VtqiHyBrayLNj+5u/8N4sfmxhu8y6uUTGaP3nqVVz7/+opzwLeVj4Z5tKGpszGP rxwa/55YLyax2myZofE+cn48QWplQyJdOKX2DP5niwPZZQUfFiDwEVhUzYVJvCcKwHZv QnswQeYdzqu8LL0WM5xi0Xbv2rLI0uxL+HYCkvACua0R05wfXqkNjcZ4+cWdvlNaozWv /PRWJw0AMB+zGRK1YLBbNUfvl5pFj/rQ/vSicyGMXFJgxjukOHGHbfbSU1W0zIoztAWX jDbqt73Fv/VZyMDSf1tSzlqOyr6tJYa1HhHBs5aVRc7gPYXAZKfhFjVash3YVepspHon sAXQ== X-Gm-Message-State: AB4q+uGqBGoQ6tVca3VwOavzXi0ej7MR1KKgcch8+1RFSySIqTPDn2n7 ON7yBDV0yHYKNT03hQcAk7N4YK08LM/IQcN/zwrWeBWmANzGKxZPINOtWU6+ePHNpyPjHuE+PYt pM44o56z6Tg== X-Received: from dyvt17.prod.google.com ([2002:a05:7301:d811:b0:385:900:c492]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:693c:83da:20b0:386:95e7:8497 with SMTP id 5a478bee46e88-387521cb576mr6335540eec.28.1796524473487; Sat, 05 Dec 2026 18:34:33 -0800 (PST) Date: Sat, 5 Dec 2026 18:34:07 -0800 In-Reply-To: <20261206023413.3078292-1-irogers@google.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261206023413.3078292-1-irogers@google.com> X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog Message-ID: <20261206023413.3078292-2-irogers@google.com> Subject: [PATCH v5 1/7] perf machine: Fix leak when creating host kernel maps fails From: Ian Rogers To: linux-perf-users@vger.kernel.org, acme@kernel.org, namhyung@kernel.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, jolsa@kernel.org, adrian.hunter@intel.com, james.clark@linaro.org, dsahern@gmail.com, andrii@kernel.org, Ian Rogers Content-Type: text/plain; charset="UTF-8" If machine__create_kernel_maps() fails in __machine__new_host() the machine is freed with free(), leaking what machine__init() and the partially created kernel maps allocated, such as the kmaps, root_dir, mmap_name, kernel DSO and threads. Use machine__delete() to release them. Fixes: 8fb598e5a3b0 ("perf trace: Fix comm resolution when reading events from file") Signed-off-by: Ian Rogers --- Notes: The leak was found by the Sashiko AI review tool when reviewing an earlier version of this series. tools/perf/util/machine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 2750d507aecc..5fbc5941a2bc 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -144,7 +144,7 @@ static struct machine *__machine__new_host(struct perf_env *host_env, bool kerne } if (kernel_maps && machine__create_kernel_maps(machine) < 0) { - free(machine); + machine__delete(machine); return NULL; } machine->env = host_env; -- 2.56.1.915.g69d5ec7298-goog