From nobody Wed Feb 11 02:24:33 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A6C624677F for ; Sat, 24 Jan 2026 16:47:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769273224; cv=none; b=OTHEHrZXf37WD9BOxSRwQPDQ8QGzEXcm8llvLdhJPZyMddk709Gn90ORH4Z2F0X2fZb9WoI+BomNh90W5OD3n8f1VcIYB64uKRAb+pzqU/PELkaYeUoMJyaNaAQmRcotR43BLUD6rOHMsj3n4lPTlpg0qDcQFLm45PtTY430hOg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769273224; c=relaxed/simple; bh=Loik4NtpaUGTgbbPGsqPlqeVdsjyh+lsRwTPRfSGNkg=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=GKZ3KIPFOxyOCGPhbPlDgkj3rfm1o0R3GqwjX7FoOUca8+3gHfdV4zZ/XJTmSful/m2Fh70oTZOT2Tp7FFqdmiA7izy3e7whbd6zOyQDeBaeXiiJtdW/LQCzqKQKUJLq0zBMRvsGo5U2OszYCjw9MseE0sf5vEPvlYyBq0U6atU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Mmu16mG9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Mmu16mG9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28541C2BC86; Sat, 24 Jan 2026 16:47:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1769273224; bh=Loik4NtpaUGTgbbPGsqPlqeVdsjyh+lsRwTPRfSGNkg=; h=Date:From:To:Cc:Subject:References:From; b=Mmu16mG9rMDAr0ywAb0uJCUKsEAnTPhiw3EiSDxhGt02U9ow93APGUr0m88YQDOgo 47dsOiZoza1ro0FdLP6hIvaYZLPlg0a2EQZtkzI6A07C6MIiPuN8Lg0IKZRndKaHgA WpIe31xap4ZlNEaJUrvr+dZocjDVlQgvjHoUTpuICmPe5Hzwh9hAfYdmFRmDlUe3Qp yYWCoE9/mVtNDZkx4/CkI0YIfj+LK+lmiOUaz1QbAmRco7OVRnaKVPOeML8J+Jddea n0b9L7ECFO9LEQ5biqFrw7g7xcuBNJhAVmmqS25S8bhsVHdDGO8bmYuS438xpONq3a rmJBaYFUdbggQ== Received: from rostedt by gandalf with local (Exim 4.99.1) (envelope-from ) id 1vjgnP-00000003CoM-11fh; Sat, 24 Jan 2026 11:47:35 -0500 Message-ID: <20260124164735.123784124@kernel.org> User-Agent: quilt/0.68 Date: Sat, 24 Jan 2026 11:29:47 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Weigang He Subject: [for-linus][PATCH 4/4] scripts/tracepoint-update: Fix memory leak in add_string() on failure References: <20260124162943.928691049@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Weigang He When realloc() fails in add_string(), the function returns -1 but leaves *vals pointing to the previously allocated memory. This can cause memory leaks in callers like make_trace_array() that return on error without freeing the partially built array. Fix this by freeing *vals and setting it to NULL when realloc() fails. This makes the error handling self-contained in add_string() so callers don't need to handle cleanup on failure. This bug is found by my static analysis tool and my code review. Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Fixes: e30f8e61e2518 ("tracing: Add a tracepoint verification check at buil= d time") Link: https://patch.msgid.link/20260119114542.1714405-1-geoffreyhe2@gmail.c= om Signed-off-by: Weigang He Signed-off-by: Steven Rostedt (Google) --- scripts/tracepoint-update.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/tracepoint-update.c b/scripts/tracepoint-update.c index 90046aedc97b..5cf43c0aac89 100644 --- a/scripts/tracepoint-update.c +++ b/scripts/tracepoint-update.c @@ -49,6 +49,8 @@ static int add_string(const char *str, const char ***vals= , int *count) array =3D realloc(array, sizeof(char *) * size); if (!array) { fprintf(stderr, "Failed memory allocation\n"); + free(*vals); + *vals =3D NULL; return -1; } *vals =3D array; --=20 2.51.0