From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.70 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796365415; b=Lzfyj3TK2ZIdDYapgdX4S15nRUjZWkAUDDPSftFX1aaoBut8yt5ALIR1YgmG4/NSt9L0 HK83yPEXLtads9M87QEEyPQUaYplai6zCeMKFnYbXpH+H2asCeeuRln28YGoS4ewMRsWs G80Nld6MA69EvoRPLz9AP9pTpEpLkl6uWNC4JmYIj2vLxvChxyURCt8noFJalftfEz7uH DxP1JFNIerkCQs10ME8mDprS3r8sYcpeDFYNg7rM3BY2XSGQl7/+8OAEHfgYqQrU3/NZ6 345VyKuLASS0wEfHhTrrJbyoJgvICorKwGEE7Bxd5tmWFN77ue8QNZAXpkwEemLds+g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796365415; 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=QwIbPDyza4u9hkYSGyuWGajgk3pzpzqcJQ4XfQoL38U=; b=ArJx9BP+BRciEX4DhmE8dL9/MyAeY5mfPueuIE52yBIiASq8YreGDHRDhVrlXiFh60vt R3wOECDxY9MIVfP+t8795ulJxdtYOxOZROMXb5bo5FJWqYB7ZF4k3eSiVHq7EHXr4lBQb SqQhREd6Fg6E7LQN3aWEy8gZcLJpBWHkip+/59gjq6snA7Ad/+mo7kiAVRV4i3GOrzQ0P ++U43yF3zJ/I8TmDLy1DBx6fkGX62K68QlZhIdV5EeWQ7ufqp6zPxCbnfun+5de5VAJ1T vkSVoFphWKK7NWBc1duKFjiG58+qQ1CrXnhIxJYlk5hN91oNDIAfmIUl0QSLdqffg8g== 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="H79/qWK7"; arc=none smtp.remote-ip=209.85.210.70 Received: from mail-ot1-f70.google.com (mail-ot1-f70.google.com [209.85.210.70]) (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 C60A3606A33E for ; Fri, 4 Dec 2026 06:23:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C60A3606A33E 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=H79/qWK7 Received: by mail-ot1-f70.google.com with SMTP id 46e09a7af769-86320da67fdso909890a34.1 for ; Thu, 03 Dec 2026 22:23:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796365414; x=1796970214; 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=QwIbPDyza4u9hkYSGyuWGajgk3pzpzqcJQ4XfQoL38U=; b=H79/qWK7pMQra40232bIiB35QEO7u+0fuZPXrJ35d+Y8nh6k0hoiY31N0C67QK4v7L YutbWC6i22uXYAC8fo5cgTQ0TxnIFxBe2npn8s5iuRnVgIQmuKaqIdWf3AqTfLRnIKrD DDyYKJY3ngh/4NvMUT0qMAS0MWOTcYezf9B8upvT8/c0CvG9a7DXTmV1F1C+J0u7LEMF plbsKLZVbGRgfTEiW12HkhzWK1OO4JKBl18n2MjmMFGlxcCL2Q5WUky9kNLdLblPynak t6btEzccCQBMieL+RUml2R6pudqPo2iTmLFXi50QLNq/Bfirmrsv6mGHe204Yt/+HK1E taNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796365414; x=1796970214; 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=QwIbPDyza4u9hkYSGyuWGajgk3pzpzqcJQ4XfQoL38U=; b=sEMg3PZBE1kgZhqTRAbXSvoQuPxkTyyMwevSegjGPKVRCpk5Nm1QholYu2VUiR8vG2 cLG6jUcH5I1Xq65kf2Thh3qZgo3gxMl3skLwFIVBQM1igS8DaAQ7ajZkhd+3xP4fmCSB HRX4Qn7pjFHKEvBOHpLbnFnZPEHOz418DLdDIT4uXpI05UOKVt+ZRyGc8cK2I1nQuUW9 +RAUxTtyHb2jIA5CxuIJiH9/1c6tJV4t1wHAm03lgaDp9sq4qePxhW3q+oeiJ6UEY1oC QPNtCafBLgQ5pUWvQeS4dnnwYv43tKDXEHPQS3DiE+CGUc0rA2/HyApOC8FEfVJdvzST M2Mw== X-Gm-Message-State: APuU4Z8gLGnoSoNNqiMlhgqRFmeFbcWVqLwpfFPSifYXUXwI0QbJVB7B aEwhhNj70/5nXiplXRqgepLrd9yq58LAonr4PgYk960fGx4m56WBcZkdIqQMR7DcUgJdAAysw7C SKkLWo284KGc/i2taDkYoYtp5YLTpG+/i+VoLMEx++4a+zHzt+6WtNftP4M5mtSWM5HfidU14sE Q8l2HxHBavVwT+PRPYsUXszlG27LeSxbEVl3aQ6t4EUZQlU90eJT77dwo= X-Received: from otqh8.prod.google.com ([2002:a9d:6f88:0:b0:862:94a8:fa5e]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6830:4103:b0:7f6:96ad:36a8 with SMTP id 46e09a7af769-863f898c970mr909788a34.8.1796365413407; Thu, 03 Dec 2026 22:23:33 -0800 (PST) Date: Thu, 3 Dec 2026 22:23:22 -0800 In-Reply-To: <20261204062328.2508164-1-irogers@google.com> X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261204062328.2508164-1-irogers@google.com> X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog Message-ID: <20261204062328.2508164-2-irogers@google.com> Subject: [PATCH v3 1/7] perf machine: Fix leak when creating host kernel maps fails From: Ian Rogers To: linux-perf-users@vger.kernel.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, 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; -- 2.56.1.915.g69d5ec7298-goog