From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.71 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796365415; b=jdktqkPpYr2DsJ+pDLf++pmNIUSOiXuk3XomK0LhyRdzVp24oca5TE8ebG26d1BEhypf C9DlhgQbKohQLe3F8ninze9mbhMuzC+0kvMgQ1veEBo4hz7FrshTmjn4XwwQBkaow0udY 1797gWRWrTY4lLiSfDiJjemfmeVLD0PGNH8ZwRNS+X/daZDZLck3t2z89+P95BfCDNaG2 0iyVZYihSkI99GTgTgTbUS1CoRQTvdOndcB7hF3t980tc87vrMPbQGrgkI+m/ER7PfY/2 xJRw8Mbq6OJvPvfEZKY0Qwlr/jFYxLKKFoaW9yhpU498RwTnB7wU4UGO/zqKYikiA9w== 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=a7keWhIY+p9dvJdXU0cgNVLMsf8Lmdp0GJOfDP2IUNNp3CPYATF6GCPzdbDuSX+AqzVZ qM+gJuE0R70NSfQlBZ5tTU5gyFwz+votKyI0lt0Z0CzJ0kkXCnyeV5N7EumavzE+oeqVX HLZ/eYPwbQ97HFztgPV3dOKvqjGdrlijUDSLEg68DrvJXSOe9IJJjJiAaGyVgaWmr8+SC 4bp39MP5Cd00g1EDK3I1+7FQs9rkGuobC0K2aCd0FARXywhlgEdS488mO8hLTdoFisDT8 +Ha8NQ7WvNFtxUBBDQjgDR40dt7Ko5HQfxMEgeGyeTt4qV76sHr9z1iy4cJDvryCyww== 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.71 Received: from mail-ot1-f71.google.com (mail-ot1-f71.google.com [209.85.210.71]) (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 B7DB9606A33C for ; Fri, 4 Dec 2026 06:23:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B7DB9606A33C 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-f71.google.com with SMTP id 46e09a7af769-8520e83f715so832590a34.2 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=zQTTP9Ulu3IYRbedYEQFs7kqTrNcXk8bta2jf2UhOv4upvQKhBhrY4NmH11vHMivgc o/dg2g0ThA9Wwba8LCo/w1LF446mImxma6duxRWld3Zpo+Z3+OLvhO1zVoSRucRaOMj8 8Jia7wBp1QemdpgFnBVZlzIgHZImjbkodLDmc1lhjbpsspr+290aS1m8S6Yqy3eQ7QaX mLKrxTeL6/2Q5FPfCncG/nCRRTUx2iOvGuS0d8w7647qX1xFdI6dkyOaeaFBlfESsEMV wdQ2SR4RDgUE0Ehu+0Fpnz2ekgI6BEikWrEnufTVRqUNb/yxKM1U0I4A8Nuiv+rtZ9e4 h/xA== X-Gm-Message-State: APuU4Z+V5TCI+0uYVMuFPS92EVNMlhIilDV0okyWPdKvFhbJv4Web6si bxlsa4JhSBfPMl6Kha8CklwiKfp100ucKIv8DJoE2AuwQOFmbmOfDGTH2qjJCvliyKc6rUmJg6W 30w/fPA/8Sw== 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-kernel@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