From nobody Thu Feb 12 07:39:07 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD7FAC77B78 for ; Wed, 26 Apr 2023 17:18:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231848AbjDZRSM (ORCPT ); Wed, 26 Apr 2023 13:18:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234745AbjDZRRx (ORCPT ); Wed, 26 Apr 2023 13:17:53 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA25D76A1 for ; Wed, 26 Apr 2023 10:17:52 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2C1F663712 for ; Wed, 26 Apr 2023 17:17:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07E1EC433EF; Wed, 26 Apr 2023 17:17:52 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1prim7-005Kc7-04; Wed, 26 Apr 2023 13:17:51 -0400 Message-ID: <20230426171750.842971434@goodmis.org> User-Agent: quilt/0.66 Date: Wed, 26 Apr 2023 13:17:12 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , Hao Zeng Subject: [for-next][PATCH 09/11] recordmcount: Fix memory leaks in the uwrite function References: <20230426171703.202523909@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Hao Zeng Common realloc mistake: 'file_append' nulled but not freed upon failure Link: https://lkml.kernel.org/r/20230426010527.703093-1-zenghao@kylinos.cn Signed-off-by: Hao Zeng Suggested-by: Steven Rostedt Signed-off-by: Steven Rostedt (Google) --- scripts/recordmcount.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/recordmcount.c b/scripts/recordmcount.c index e30216525325..40ae6b2c7a6d 100644 --- a/scripts/recordmcount.c +++ b/scripts/recordmcount.c @@ -110,6 +110,7 @@ static ssize_t uwrite(void const *const buf, size_t con= st count) { size_t cnt =3D count; off_t idx =3D 0; + void *p =3D NULL; =20 file_updated =3D 1; =20 @@ -117,7 +118,10 @@ static ssize_t uwrite(void const *const buf, size_t co= nst count) off_t aoffset =3D (file_ptr + count) - file_end; =20 if (aoffset > file_append_size) { - file_append =3D realloc(file_append, aoffset); + p =3D realloc(file_append, aoffset); + if (!p) + free(file_append); + file_append =3D p; file_append_size =3D aoffset; } if (!file_append) { --=20 2.39.2