From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.69 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796360399; b=2A89PEoT6Kf1Avg5QalD7EKKgE7vBdPi+VZjarGk3JkdrXKsTbQMzBswNwA5LhPaMzYe Fqq7RSUIPWtcSrIA18Qc3rOaphzJuZoPUVLJNeoj+TbSKOLkCNmuHbQFpN5yEUGcDyxoo gljgT5YXtUr9VzOT13rTloc0iXrEtRzXtVGo2Z8S3yS2J1A6t9mtWeYd4EwTOa+x7tIR7 744O/kZZIkQsVRf4Hdc1FPpxdLZ4Bi7QjGQcOydShmc9ri0K/heHeT/ygScDTCGbiGE1V IcWPLpNZfX9tIqLZGCgirRkgh5ycibOCu4ux65ogqG0scxIvQbbeC+fR7EpnIdUBmnQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796360399; 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=mG1XqTBObVXpG7DaFld2gZrerl8g5dXOvv8J3bs2ytU=; b=3zRadEb85oWdMh+7ed5Go8mqFGF/YXtOFA2n0Rka+J0oElN8yKJWu3lKOSiVVzkdkcqg L5ahwqsWlmmji4Zg3CF6gMj9XNixilfE4XW0CXMQcDsPczbgRDZ/GbQoEjJScTo5F87eH RDhgLWdzSAnhRGOuu2QHnVSmTlXUzjnHDan+go+SZ5nFl6IZo5WFUuvmvSL4LQKzIX7W7 IhE67oOpwbLC1jDHfXTQx7uloQ3mC/I4DLUu0E8McQjLb3BHylP03TJgIJJx0cKtNOXrE 8DR7KCOL+zE9ZVr2lWYA5rJwAplonfpi+F+71cWvD2bxFOkzmFrimXhgtaH5B8K8YhA== 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=ASEjN5oo; arc=none smtp.remote-ip=209.85.160.69 Received: from mail-oa1-f69.google.com (mail-oa1-f69.google.com [209.85.160.69]) (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 D1B60606A682 for ; Fri, 4 Dec 2026 04:59:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D1B60606A682 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=ASEjN5oo Received: by mail-oa1-f69.google.com with SMTP id 586e51a60fabf-4943ed99826so700775fac.3 for ; Thu, 03 Dec 2026 20:59:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796360398; x=1796965198; 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=mG1XqTBObVXpG7DaFld2gZrerl8g5dXOvv8J3bs2ytU=; b=ASEjN5oo0xxtMQzcCZPy6l4t+49oZjUE0EmiHZvB8pmSxvLNT+sKW8+1a3dGuGNhgk 9tay93cP+IxY+fK/wyw87UTOEbKxal+i4QAwwzml7gsauzCpjZPVr9+YIMjdEhlqZjHL 8VRqAj2YoRbashgg7nU+7UXpEsP4Wh9q+Hv3ZaSRmyfGeJO6YQIArmfigiiPD53BQ/CR D725X+0eGNWpI1acWOLMt5MwVbQypx6OWHLJyFDhtnbHZyW4psQ8STzLsv+KPMy3dS6l AQRh7OYEQ2VPHBDYnoPFwpfaBPq/Al6qXe8Hb+grpTbuHlS2BA38P2wIOFOUq0e4e97G xbWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796360398; x=1796965198; 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=mG1XqTBObVXpG7DaFld2gZrerl8g5dXOvv8J3bs2ytU=; b=VMAD77eM2qs/AGOLatLPVZRbbxP/5pNfIuFbEKBqOzQZ4Qbz9SQAmQ2QuYgMcGVjGQ zqM5oGB6kmU34iB3mNo8m2O/9/Rm/BDbKPrviEAOTb0CbdD8TIFmk44N2YD+PUskFJbj QY+Kfsx/RUJIFtPcHNbzj+mNib30QqDG980rZBe5BiTLyvuQIx35IzEqabQlQJQBDq66 zlAhFoiE8V9hmPFfq8Tvz0O96t4HZ8Pc/facQ6M7HoABOag8BlXGx2UjasKUZ5e2sTFR JISxT0zQQFToVpa2gfH1jYW1YbfASfKSL1lDyTW36N090UN5d55Rv1ygxqOysmFoRQJY sPqw== X-Gm-Message-State: APuU4Z+YNtnZea4ECrGMu+oVPnZ7Q/lWS7pqnrskQ1+0QVmFNk6L+Lw1 O6aJMctaG8ocppzbjhA4/1etGRBV8XzAYiaL5Ol+M5jYDu/ctZfZUzQvdtdCK+zBvzy6DU5GeKq 1+V1HvNXFjA== X-Received: from oabgw10-n1.prod.google.com ([2002:a05:6870:a14a:10b0:4a7:1cc1:e72]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6871:c8dc:b0:4ad:949d:1993 with SMTP id 586e51a60fabf-4e3d1127c02mr720820fac.8.1796360397403; Thu, 03 Dec 2026 20:59:57 -0800 (PST) Date: Thu, 3 Dec 2026 20:59:43 -0800 In-Reply-To: <20261204045948.2254888-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: <20261204045948.2254888-1-irogers@google.com> X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog Message-ID: <20261204045948.2254888-2-irogers@google.com> Subject: [PATCH v2 1/6] 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. This change was developed with the help of an AI coding assistant (Gemini in Jetski), which wrote the initial code, tests and changelog; it was reviewed, built and tested by the author. 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; base-commit: 22f7d78dc87e43ff4f7c03d23f46f49692c41ad0 -- 2.56.1.915.g69d5ec7298-goog