From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.197 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796524475; b=r3qqu+WOLfZUNaG40/2vsYTSVCLmR5Tky9xU1LdM4CdAq5DKVw1zKL/lU5q84OlQliaX /DwyAz/bJXCFjb+8fOEPKMOAU5CtCVQL61P4pGOtjZEo+Iy8jbbGaoUVb+Ydmbc7gRqZi 3yolFwo14e/PLkJba9qoCEPE1F31TLSlw2lwM0Q3yg+vkldwyhFtuRobYFoVMLUuGDtPL 2gZAzIr350I8FvEuFfsvczsTAsBxhSMYzEMwzfTReTTc905V1eDmkFX7PFLsIoQyhq9L0 yXIQddxVD9yxc/SiYNPU4TahETPXkvnmzP1x+g7J8Dz1Qld3z0aYxtVjsknL+lZZKhQ== 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=CbEcOPQ/Xm5NXI9bqvBOZ/IQ08OYRZhGEB2/sj0ltQZU+2cdIU1gXQeZo0qOCDlhJsiz BsKM/Ks+ubUBnkV56zgEKXrxfM4L8g501Ewicu9xTKUM3tixro3w3qh+GsQheh9//bBzM AIqinL78OhoVMsThCajKOQ/Mst9IIzfuNEF+96V4HmRqlcB47YiVZ3TioTA/flmnUt8sc tae1Eqg0HxrWmLmu0W/22ii9/Ga+9Xkh35W+Vn91mYN2wRcL9ZvjcsrIvei54GeT12MDf tuOsOR5tp81IshV0lui8dOPe7C2070DzpN8CqCmfrJslaIQmZXEdO71nTjCY4il0J9A== 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.197 Received: from mail-dy1-f197.google.com (mail-dy1-f197.google.com [74.125.82.197]) (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 D4D83606A31F for ; Sun, 6 Dec 2026 02:34:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D4D83606A31F 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-f197.google.com with SMTP id 5a478bee46e88-33c35f5ca6cso3381075eec.1 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=kCZS795U1CAPrEXEjJfisc3E3BXpLrhuoEp1RuGkohslOHDWpeewGRVq+O1fcszolK j3qOHN/O15wG2iW/IUMiESgsQvFkZALXRJl4D3msr8R7TU9oHymDon+mAPqF6C2KwqIY w6CR8mLHYnnlNaGjgdpRpDT0QjRH87MX1Cc2J57PB0VM6vCqrKYVpvzA96ZkyAAP5M9m aoJLQwZE5PA4d8CgJqrdG4kAxjKQX2ut6Kt0BDLAe1mIKV0JIiOw2+eE9tjhyFkEwgx4 DAgmFHM3SvARv9tieEKNevXbHZWfHkopyfy6F9olR80487OTMd277nfQr4DnmxJUrLDb 97EQ== X-Gm-Message-State: AB4q+uGIQJ58aE+1Ot2jn0ZrdcOA78lMm1athOi5L69r9yhBXtlwiEZT UoXJSqPgKByHgu1uLwbDTtw0yYn0kreSdTPyMjhUGd4kuJK419bL4I8PTQSlbhGCfNQI8syzvEQ zBssHiGy27frxJMlOjsxLdxN1F+qDDjZ+ViZsw55jaDJsEeKuSrOuUskL0WKZReHIApQP5F8PdZ l4BVk97eISF4C4IZh+FSezIdj2SR6U6U9MfCEub13QzpeTZAR+Xe3E61s= 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-perf-users@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