Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp685027rwl; Wed, 12 Apr 2023 02:34:27 -0700 (PDT) X-Google-Smtp-Source: AKy350Y8uMs+R7sdiUYQ+/KL4TN1SPlXgrARYKnQoJ6XG6b7Qj0sBhg5frbZUy0AZLHsPDXU00VY X-Received: by 2002:aa7:d797:0:b0:504:8173:6238 with SMTP id s23-20020aa7d797000000b0050481736238mr1679240edq.21.1681292066844; Wed, 12 Apr 2023 02:34:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681292066; cv=none; d=google.com; s=arc-20160816; b=KAlTujuGQRN0meD+2sIcPSZmzz1ZWUvX+os7posirRpYZX9yYR/ydt4SLh8FpFCLNk VtAUsFXntwpFDUl8E3ln6x2iLwgPaHhJ/ZDs5F1rwCdtw48aQw1oJVKNq/o67U8+CeNP pvcpevvlmMmabrN/wuCfFya81a7lDF7R30OZFbiW74tLC7CQGbNf9KFkeI+O3K1N9l8h TdTR8vVQG6HepvOeketsRNCOedNDR5JyJPnsAC0fn4aZdlH/IKom/7ogLYG/CuUCBxo4 QMpas3HQj4KkcJ4Pu/MrDLt1Zwck1J3ezHNKGi8TZyi3FO0GjE/PpPlJbHsbTZNto5im /Pow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=2V++rThavmiaureirLTqK1I6esbh086ZdHWg4Bnudjk=; b=L5IRBtjD1jekIzv0FHIq2qdwgcbi1kbTjkzJ0cULKiOZer7xIf0gze48OhFBVlCoPd 5ZP79My7s2aMISCWDMoK6Qr1NfTaqYK09LdN3GjMqHUTEUT9pSmXAvcFeQPJGTzVQmXu 3Ye0PLR7PWiJetmgKzjo+VWYGsRbHV4RtOCKtL5mb57ZzwERKo04u+9nVfbfOB1O6UNM vxW77NsoZbhk7M+qRUzNXWeSwuVddPdHn5Lf4OMWDvzVeTzuFw1dkmvqqJID/Utw6mBh E9lZbtqwmpuszzqRALnKmEi7PV/5FQ0eHQJ6GjON4m9MN/0+954xEJPFMjUAjlqc0UBC TTyA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n10-20020aa7db4a000000b00501d7cdf513si1412665edt.126.2023.04.12.02.34.02; Wed, 12 Apr 2023 02:34:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230520AbjDLJbi (ORCPT + 99 others); Wed, 12 Apr 2023 05:31:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231501AbjDLJb3 (ORCPT ); Wed, 12 Apr 2023 05:31:29 -0400 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C950561B4 for ; Wed, 12 Apr 2023 02:31:10 -0700 (PDT) X-UUID: 977d1cfac60f42e38a9c55505f7af3aa-20230412 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.22,REQID:018868c1-4bc0-4ec3-9656-5f7ae3677c0a,IP:5,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-10 X-CID-INFO: VERSION:1.1.22,REQID:018868c1-4bc0-4ec3-9656-5f7ae3677c0a,IP:5,URL :0,TC:0,Content:0,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:-10 X-CID-META: VersionHash:120426c,CLOUDID:9e5ad083-cd9c-45f5-8134-710979e3df0e,B ulkID:230412173051028PMDJ2,BulkQuantity:0,Recheck:0,SF:24|17|19|44|38|102, TC:nil,Content:0,EDM:-3,IP:-2,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 ,OSI:0,OSA:0,AV:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-UUID: 977d1cfac60f42e38a9c55505f7af3aa-20230412 X-User: zenghao@kylinos.cn Received: from zdzh5-qitianm428-a376.. [(116.128.244.169)] by mailgw (envelope-from ) (Generic MTA) with ESMTP id 1359329413; Wed, 12 Apr 2023 17:30:50 +0800 From: Hao Zeng To: chenhuacai@kernel.org, rostedt@goodmis.org, zhangqing@loongson.cn, linux-kernel@vger.kernel.org Cc: Hao Zeng Subject: [PATCH] recordmcount: Fix memory leaks in the uwrite function Date: Wed, 12 Apr 2023 17:30:48 +0800 Message-Id: <20230412093048.3005276-1-zenghao@kylinos.cn> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Common realloc mistake: 'file_append' nulled but not freed upon failure Signed-off-by: Hao Zeng --- scripts/recordmcount.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/scripts/recordmcount.c b/scripts/recordmcount.c index e30216525325..2b7173a86d4c 100644 --- a/scripts/recordmcount.c +++ b/scripts/recordmcount.c @@ -110,22 +110,23 @@ static ssize_t uwrite(void const *const buf, size_t const count) { size_t cnt = count; off_t idx = 0; - + void *p = NULL; file_updated = 1; if (file_ptr + count >= file_end) { off_t aoffset = (file_ptr + count) - file_end; if (aoffset > file_append_size) { - file_append = realloc(file_append, aoffset); + p = realloc(file_append, aoffset); + if (!p) { + perror("write"); + file_append_cleanup(); + mmap_cleanup(); + return -1; + } + file_append = p; file_append_size = aoffset; } - if (!file_append) { - perror("write"); - file_append_cleanup(); - mmap_cleanup(); - return -1; - } if (file_ptr < file_end) { cnt = file_end - file_ptr; } else { -- 2.37.2 No virus found Checked by Hillstone Network AntiVirus