From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.71 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796360399; b=bcWlTFuh1Un459kBSlFXtE+QL5T6dznSfxgU986aZdsvC6TRdEZal4jifjwFy56JFLZG HVaSOMwtPuf7iitQLCRSsEh3f7N6UwnxB3FMLB2/QL+VzIHJMYNJynpOgyU3Cx/ocW9oG NB/MO52zcWEoMumZIbmRZFsTVxEsg/cS6CdcXHJIiLZfDfEQjoskGebUitLfN3rjTfPoc KMS4TRaS3R2MJ291M0Gobwlz1mlDvae3ESA6t9RadxWZpGbRwhOwpgx5AAfbDbUkT4The wrjwQ6pvw0dioUUKFzRxJq28t2qy4UUHn2axgl/5kptKAqjIvrdYj7Hahe/ou6f2Q6Q== 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=UN3vfWzgMz4GXSGQM6o7XcUXTkLLBNgah4IzEyNxh+A38otiRd4WC3Vs1iMnxbwfhmmi 8vSisKHkRIAi8fEnNxWYUDbMsRPCnfM9A9M4ViyQScRLcFu/YDS7HZiByNKVgRk6Jh/32 yKFPDmq0MEFzJV89YbPlSaDclKWZu0FPW4klnFpnteR1Rng4g0irP1I4WlMOIXhlxgjqs XeLYOLvS/10nbdCNXiEIupRZgqxLuzKog2lIMomYhjInaGK9HO0i7g1+qTgdFiYBINZFE 96WXAmtISIRMwkYX1iThvYEC88Yg6QI2z1EbQOPsy24bf2ah1sZHVEJ6hh8mRStEdjg== 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.71 Received: from mail-oa1-f71.google.com (mail-oa1-f71.google.com [209.85.160.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 D28B3606A683 for ; Fri, 4 Dec 2026 04:59:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D28B3606A683 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-f71.google.com with SMTP id 586e51a60fabf-45a07949855so701373fac.2 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=ZFUdk8+5RIMRcl7KZdfAJop2xFvzLd8NbIUCTiWKD2ujMFz3Ko1bv+PlXUbWn/mhKK HrPEwHPFajAOGyOPrXnt6lKPChAKE+Q4E5+SjhS3bly6neaj24glk0QFAXm4XpqDpp1P om/ypXLBjq0+lU+dFqw8c8Jsq1d+PpSWcALBUI6lg8KJUw9fqHg2SBm1VesAQkaie7qv Uqd/qpq4C7mUejGv0K779loqOfZ/Vdb+o3NHbY1M9rGmqFG27InOAsPUhiv+gWZxDeX0 nvnoE2C9LoyZFYTGaejH18ge1dfPcYImj59s2/IThJNKRo/bqFHmv8oZ+5PONi3+UOmJ oLfg== X-Gm-Message-State: APuU4Z9O8dGNyMz5fYK2udrux5+CoUOZEq6mn4JI8mzsxS7P5y0Tnz3l VHd9yuzxk4LfekH8JZZO/haVR6h9PFM6xQe5Z5lT3ZUpTvMj/DR+QUghrDk6v1IYdUjEWksEYE/ QWj62/B8uRe7Zr88TwAm519F44XoxyiZMfbR0V06EePYI983Qs1YgjXOeR/yUoD2tvEABHk+9yT y9UO97cL1iPVzIRs3i35liBK0++/TrBCuH6PL9o7Wydqq9GsXd1JsUdOI= 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-perf-users@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