From nobody Tue Dec 16 16:41:33 2025 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 A5500C7618E for ; Tue, 25 Apr 2023 02:46:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233036AbjDYCqR (ORCPT ); Mon, 24 Apr 2023 22:46:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230093AbjDYCqP (ORCPT ); Mon, 24 Apr 2023 22:46:15 -0400 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B35C55B2 for ; Mon, 24 Apr 2023 19:46:13 -0700 (PDT) X-UUID: 5a77b4e5fe374127bc4d8799d8dd4900-20230425 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.22,REQID:beda3708-87cc-414b-ad35-f528de7f85f0,IP:10, URL:0,TC:0,Content:-5,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACT ION:release,TS:-10 X-CID-INFO: VERSION:1.1.22,REQID:beda3708-87cc-414b-ad35-f528de7f85f0,IP:10,UR L:0,TC:0,Content:-5,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-10 X-CID-META: VersionHash:120426c,CLOUDID:eb5106ec-db6f-41fe-8b83-13fe7ed1ef52,B ulkID:230425104609E4BQ6LXL,BulkQuantity:0,Recheck:0,SF:24|17|19|44|102,TC: nil,Content:0,EDM:-3,IP:-2,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OS I:0,OSA:0,AV:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-UUID: 5a77b4e5fe374127bc4d8799d8dd4900-20230425 Received: from mail.kylinos.cn [(39.156.73.10)] by mailgw (envelope-from ) (Generic MTA) with ESMTP id 779924533; Tue, 25 Apr 2023 10:46:07 +0800 Received: from mail.kylinos.cn (localhost [127.0.0.1]) by mail.kylinos.cn (NSMail) with SMTP id E96DCE0084A1; Tue, 25 Apr 2023 10:46:06 +0800 (CST) X-ns-mid: postfix-64473EEE-754331113 Received: from zdzh5-QiTianM428-A376.. (unknown [172.20.12.253]) by mail.kylinos.cn (NSMail) with ESMTPA id C4940E0084A1; Tue, 25 Apr 2023 10:46:05 +0800 (CST) From: Hao Zeng To: rostedt@goodmis.org Cc: chenhuacai@kernel.org, zhangqing@loongson.cn, linux-kernel@vger.kernel.org, Hao Zeng Subject: [PATCH v2] recordmcount: Fix memory leaks in the uwrite function Date: Tue, 25 Apr 2023 10:46:03 +0800 Message-Id: <20230425024603.4005251-1-zenghao@kylinos.cn> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Common realloc mistake: 'file_append' nulled but not freed upon failure Signed-off-by: Hao Zeng Suggested-by: Steven Rostedt --- scripts/recordmcount.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/recordmcount.c b/scripts/recordmcount.c index e30216525325..efeec898f632 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,13 @@ 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 NULL; + } else { + file_append =3D p; + } file_append_size =3D aoffset; } if (!file_append) { --=20 2.37.2