Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp7264240rwr; Tue, 25 Apr 2023 10:16:41 -0700 (PDT) X-Google-Smtp-Source: AKy350ahOUPW7JRZkhyj7I5YmL1O/qWufNLU5jsJzHQs3dfNVOcJRLzYtDA5h3PHMgVKRpF5UyJc X-Received: by 2002:a05:6a20:5493:b0:d5:7f0b:f2f with SMTP id i19-20020a056a20549300b000d57f0b0f2fmr24300736pzk.26.1682443001110; Tue, 25 Apr 2023 10:16:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682443001; cv=none; d=google.com; s=arc-20160816; b=KbjKU6htckFSwI9O71U/uojlrxqeyYAZ26bQwgxaSs+JElbOZzjPnkMPdPVWq3WUmT lczx1r0ity/22zz9VqxFbLgVgG474VIZSvh+j6+zGDAOi+wjEcSyUU+HqEi/C5raYw0Q 8poXmBk1ounkv4M4HnrOhArCzMyVVZyZgILJ9/vElNzUoU5MS8OACb8dgwzCkBQQYFMT ZauNNotAYi8GnPECkvLGTgmQ5a4IKhgq0y6A9tt6I0ALKpGXkgBE1UCC8Jlj8Bg4kF5G mXLrUkDYqghagz3DbgtqMrUSEw7QOdX5SkLLuolcAnBhGIHMbCCZbG4LwKL66m+2U+IH Fd/g== 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 :references:in-reply-to:message-id:subject:cc:to:from:date; bh=geAp8gaIq1rzgnUjpL4e7jiAM2OtjkoKN855N9KStNo=; b=ysvgKq4cv6psk+haLP/M9J975pTuw3ej3NrE5DzrFzhDNpqB0KRZGosMrvjR3vl7jR zMRTkXltUY5+UJkXJmrw4W/lkZngx1As8x4GsEc5I+yUwk5jS1yjV1LgrEeQG5/cbntB anS3CcdWi7dC+rrVfwp312V7q3FF88GdbmcLPJB/L1LwC7l8AsfxgwFHR9HulpxEBHAi DfHM+79ci2JoUTYP9uWt3GCtpLVlLzSJCGNpiePF7lwgSCLI2TuhZZjQx7HVHpwMLFSe B3A5GfbJDVIjGyYF0HXBxJ75SRkJ4PGrgxRUtrU2+o6/k/X8i6RCHyPbsToQp229dsEZ 74yA== 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 e29-20020a63545d000000b00513ab078092si14826253pgm.438.2023.04.25.10.16.27; Tue, 25 Apr 2023 10:16:41 -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 S234916AbjDYREk (ORCPT + 99 others); Tue, 25 Apr 2023 13:04:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234900AbjDYREc (ORCPT ); Tue, 25 Apr 2023 13:04:32 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8C93B463 for ; Tue, 25 Apr 2023 10:04:30 -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 6DA20612DC for ; Tue, 25 Apr 2023 17:04:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41614C433D2; Tue, 25 Apr 2023 17:04:29 +0000 (UTC) Date: Tue, 25 Apr 2023 13:04:27 -0400 From: Steven Rostedt To: Hao Zeng Cc: chenhuacai@kernel.org, zhangqing@loongson.cn, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] recordmcount: Fix memory leaks in the uwrite function Message-ID: <20230425130427.39b58745@gandalf.local.home> In-Reply-To: <20230425024603.4005251-1-zenghao@kylinos.cn> References: <20230425024603.4005251-1-zenghao@kylinos.cn> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 On Tue, 25 Apr 2023 10:46:03 +0800 Hao Zeng wrote: > @@ -117,7 +118,13 @@ static ssize_t uwrite(void const *const buf, size_t const count) > 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) { > + free(file_append); > + file_append = NULL; > + } else { > + file_append = p; > + } You can simplify the above with: if (!p) free(file_append); file_append = p; -- Steve > file_append_size = aoffset; > } > if (!file_append) {