From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D11B12BE63F for ; Sun, 9 Aug 2026 07:15:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.197 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786259732; cv=none; b=kf1HZ+iM1WZv9OECBb13Ed0wCQJQUEgPkM25zg3B83hHlcjhBa5aL9PNJ8O29hji3Jwlgig6gLxxEoqvAs1DV7iASQmO8lTlcONazu5SkgAH0AzpCYCffZG3nE0zj38QDPXegLR1VoHNUf39hSNlh5/URPSfD//S5VjXz47gEOw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786259732; c=relaxed/simple; bh=8sCG0f5IGimuJ+fsQUifv2/QjLt5UBT/0kf9dJVm/O4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=q82uf1gvfy/l1xjf2cNy7SL8oM6cP3JckGVdE+BvyJwN6f2Smh+XfFBfa2HR1hC/UT0aApZFQbRKzzv1eFFyLU9L6UP8HD+YplgSTHLva4WOQ9v6gDlXLP8KZHRu8/MBoUSEV7PXcYkB0D/r+EcPOmFSWjVch2CuPLhf732Ydbo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=cVN6oE1l; arc=none smtp.client-ip=209.85.215.197 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.b="cVN6oE1l" Received: by mail-pg1-f197.google.com with SMTP id 41be03b00d2f7-c89704da8c7so1480610a12.0 for ; Sun, 09 Aug 2026 00:15:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786259728; x=1786864528; 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=guXh3nj4hXqwhdHJMCtl6P47kx2KJmAnA1aawSbLzyY=; b=cVN6oE1lbFOqwbrhrjn+B0zXUw/99ZJlAj0zGEoou/0OWomyS+/JCD51EC9idMiEbl qq/lTwR7lhl8+WhfhPyQxg4RGrWF1ADQTmFhRVLdWhG71Ubqg6UEGOlyX0LDM12n14L7 nxG7qJJD2eYt9b+gBMgH5eB9vtD18Vo2y7/FilOF/De6f2a1FtOjT/PSas0iCqGmDBod A+IdyuRCteudpFdhsXZ/5OSIKwIG4GzE/Rq+1guXRG6t0pqjwYJPNpLiJUw076j0Rd76 eIE92uSCjTwiA+Lp6dPWFMMQCtFN3YseEWTZLAenlqXHp8G+j4FIi1sSBb/91zXZRzAF /Lng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786259728; x=1786864528; 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=guXh3nj4hXqwhdHJMCtl6P47kx2KJmAnA1aawSbLzyY=; b=RUZH78eIT1S8oMx0VVwJEYCux8Z0Gz82omve4JnbHgANq2FIzUy5pcNxJrWKcRs74T p9QEGHhSum+HZ5tBSFhdz7j3aqDMGCTME2uzHYoO/2Fy8XnJ6wiAIjfb9hEc8uvUehcJ lEAKBH5LeKWMKWrtGtIz/OG+KeHGRQ45o2eBzx1Kzm6vut9UQFJzl8tjrdwbeIkJwXQq RURJZyCef/FzFM4ciqxLZcwrHc7pssz4tWRK558wFbJMwj++9UcY+zM0iFBP4n/zWjiF +IMzo8SEj8fklzr8Csn43YNxSCmatKxs3chvvJFwfTEK99xbwbp+tundqMMZt8Ni/z0P p+eg== X-Forwarded-Encrypted: i=1; AHgh+RqM4FVo3vyaeoHVDEEhzy9j+RlBIBanCAeiI3tE/KD5A5dkk7SFpHMtkOZO4Q2HdXgFEQGSR5wev4MfsT4=@vger.kernel.org X-Gm-Message-State: AOJu0YzWgp4EETYFcA8Cn4Zod9h6evZh7Xlgt1GM5B6m34LSXbv47sUU JIN5f3E81ENZjjAJSnIpz31oRg18PlKLnDIYGq8HurVk8Evq0Z5nVu0mSdqKS3tT8g8Yrtx5Q+7 vPkCBVhmzmg== X-Received: from dlbtp10.prod.google.com ([2002:a05:7022:3b8a:b0:141:729:41df]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:e352:b0:3cb:b3fc:510f with SMTP id adf61e73a8af0-3cbb3fc5a0cmr17277123637.24.1786259727722; Sun, 09 Aug 2026 00:15:27 -0700 (PDT) Date: Sun, 9 Aug 2026 00:14:52 -0700 In-Reply-To: <20260809071455.1221514-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260624051535.3584977-1-irogers@google.com> <20260809071455.1221514-1-irogers@google.com> X-Mailer: git-send-email 2.55.0.679.g6767b8d81c-goog Message-ID: <20260809071455.1221514-14-irogers@google.com> Subject: [PATCH v3 13/15] perf python: Fix count_values memory leak in pyrf_evsel__read From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org Cc: adrian.hunter@intel.com, alice.mei.rogers@gmail.com, dapeng1.mi@linux.intel.com, james.clark@linaro.org, leo.yan@linux.dev, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, mingo@redhat.com, peterz@infradead.org, tmricht@linux.ibm.com Content-Type: text/plain; charset="UTF-8" In pyrf_evsel__read, if PyArg_ParseTuple fails, the allocated count_values is leaked. Move the allocation of count_values after the PyArg_ParseTuple call to prevent the memory leak. Fixes: 739621f65702 ("perf python: Add evsel read method") Signed-off-by: Ian Rogers --- tools/perf/util/python.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index fe5afce17333..71431c9c2e76 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -2210,11 +2210,6 @@ static PyObject *pyrf_evsel__read(struct pyrf_evsel *pevsel, CHECK_INITIALIZED(evsel, "evsel"); - count_values = PyObject_New(struct pyrf_counts_values, - &pyrf_counts_values__type); - if (!count_values) - return NULL; - if (!PyArg_ParseTuple(args, "ii", &cpu, &thread)) return NULL; @@ -2233,6 +2228,10 @@ static PyObject *pyrf_evsel__read(struct pyrf_evsel *pevsel, if (evsel__ensure_counts(evsel)) return PyErr_NoMemory(); + count_values = PyObject_New(struct pyrf_counts_values, &pyrf_counts_values__type); + if (!count_values) + return NULL; + /* Set up pointers to the old and newly read counter values. */ old_count = perf_counts(evsel->prev_raw_counts, cpu_idx, thread_idx); new_count = perf_counts(evsel->counts, cpu_idx, thread_idx); -- 2.55.0.679.g6767b8d81c-goog