Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp89131rwr; Tue, 25 Apr 2023 18:11:26 -0700 (PDT) X-Google-Smtp-Source: AKy350aJ0glMGIfow6Qhs/dlP8ab5JxaTEXdifgHLytnYl2YebWt5MaZOzIeo/PjiUq9zWC42M9v X-Received: by 2002:a17:90b:3a89:b0:247:6edf:e934 with SMTP id om9-20020a17090b3a8900b002476edfe934mr18604143pjb.42.1682471486232; Tue, 25 Apr 2023 18:11:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682471486; cv=none; d=google.com; s=arc-20160816; b=Q1ZiefQpU1QrSWbrYzDJ+eTP/szDJtK/NL6jwOLA5/3gsdB/W5/xpZoihAfifzNjnN B3eFEMvrO+ucKj+vk1GsVutseVbOXSYB3UYT5eF+aHddfjny070TFvGZ2skB26ct30A5 PK6Boga7ckGWBpfIXNdDJyMH9oa5+kvRkJl5pNpkWjBzAv1pl2Rnr7EKbzORkO2Wr2iH 5RpcP8Htb3lyZDsfzLdRn0OWrLEIJOBAFgPYAfOLo2PqdOjfOFrknEmKjA/dhsY+9515 H1fv1msWfOop4bT+Bw1h+Pchy8jb5JfRZlemUR3/Zd6vD+ed4mT4SjN6eM+XnJmmuiFM QYXg== 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=VSKMWRNWsinHQyo+6ieVlYnjdz5jnz5/fGN+HYRv8uY=; b=oD2FSctXZLKTPrIaxYB4iXbT8ypM9TzEAiRPHO1FE0TZkbbMsIU3JH9svGvwIcDxqJ WXry1wIWXKGiQNcqy6yhJB2W20DKs+/YMFIvS+AXYdDBlAuh9b71V2aruoVgXMj4Apwc lViaJiZsGCGxOnvJxOgiWM2vFBc2yUxXwakz1kG54pgcLfaLejyu30g4XMoF2i7iSOwC ffqeWLlyNEzmRNC4tqBLAedkiJStvv/kr8v1kXTYdwQI5tXrGpCH4vANUwEYUBK/MUNv 4OOVSA4mjeG1Lvp3k3NuecakcyPfgGlNY34wm6v7qLAt1FNK4nowFAPs3jqqwxWgMgBO oS4g== 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 w8-20020a63f508000000b0051b930ef848si15389976pgh.142.2023.04.25.18.11.11; Tue, 25 Apr 2023 18:11: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 S239008AbjDZBFl (ORCPT + 99 others); Tue, 25 Apr 2023 21:05:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238996AbjDZBFj (ORCPT ); Tue, 25 Apr 2023 21:05:39 -0400 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4490EB235 for ; Tue, 25 Apr 2023 18:05:37 -0700 (PDT) X-UUID: 2bfe579bd490403ea1d16fdc83396911-20230426 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.22,REQID:a16362e2-ff75-49cb-9127-c60175beaf2c,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:a16362e2-ff75-49cb-9127-c60175beaf2c,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:74f13c85-cd9c-45f5-8134-710979e3df0e,B ulkID:230426090532N6YD1SFO,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: 2bfe579bd490403ea1d16fdc83396911-20230426 Received: from mail.kylinos.cn [(39.156.73.10)] by mailgw (envelope-from ) (Generic MTA) with ESMTP id 2007136401; Wed, 26 Apr 2023 09:05:30 +0800 Received: from mail.kylinos.cn (localhost [127.0.0.1]) by mail.kylinos.cn (NSMail) with SMTP id 57460E0084A4; Wed, 26 Apr 2023 09:05:30 +0800 (CST) X-ns-mid: postfix-644878DA-15402049 Received: from zdzh5-QiTianM428-A376.. (unknown [172.20.12.253]) by mail.kylinos.cn (NSMail) with ESMTPA id A6A11E0084A4; Wed, 26 Apr 2023 09:05:29 +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 v3] recordmcount: Fix memory leaks in the uwrite function Date: Wed, 26 Apr 2023 09:05:27 +0800 Message-Id: <20230426010527.703093-1-zenghao@kylinos.cn> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,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 Suggested-by: Steven Rostedt --- 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 c= onst 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 = const 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.37.2