Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2609457rwb; Mon, 19 Sep 2022 07:30:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4xRlzvKV4pwKdme7yKYYxpn6/60AvJi2YZZWysJxkBHqEd6TLaMLG14XP/hjWXDIrL2h6S X-Received: by 2002:a17:903:124d:b0:178:60a8:b22a with SMTP id u13-20020a170903124d00b0017860a8b22amr59844plh.74.1663597830068; Mon, 19 Sep 2022 07:30:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663597830; cv=none; d=google.com; s=arc-20160816; b=lvS/dzKEM8AP40yOPET+K99ePhQnlwnNWju8dJXmVD1VAuU1sfn+3mOmL2y1nXF4nk +BGo55NAriJ+DxrxkvdzCpZP4temU5jaCySgoVVv+m9ehiI30vJR3ljWHM9NJDuWeb7Q tLFjlFfGjbc9DQ8R6Y7jOHWfx6pxjZPcUlr0naD/fRkpJ472H2hzfUAfYGy0+n16dxfi 2dGNVod+pO2G5kYGIys0k4jQ6UM6h2TklGpAMDZZcV9SPMDPkiS8MjbQnVcmvhmqLB6o E6qA5LajvxnlN51SM89zXJ5+yCgOWV6+Q+Ex0mnCbVHADG69GFWbH/qUubRqIgpg93Mz L/LA== 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:date:subject:cc:to:from; bh=Q2x9eqDxrjr6ZZxNHjDjX0z762saRtggC5GVYnhh810=; b=mJK4P2JE6on98jbmikJ7z6LQcxS2n5U8Mbcbu1HxHNLvoOPTvkqgA3RxM5SqKgKze8 ddTM1z/7OC9YUGPcN0/T0oSxXL5N99ca/iYTALUQf/GCFZYvZw5EBNpRSOag7yQkvigP elcyoB7G/IMG9re+rtfT9TR/ZjMzxsrkJecDCiLDuOYi4Rw04qRjWgCpd4dhvF+ZhpbI veR32eXizHUCsdvf3YpneMTYh8BtkA+Z0hAQUGwGkov5aaE1dmcxGHFE4jM1Je+DRR3O oMgAds9qHdsl7Akj23B+41VITqVO52XqLDyUkmMGTZbAS3VdPCp4wFCHUuDdZFuCNTAH UxQw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 74-20020a63024d000000b004393f62586csi6018927pgc.238.2022.09.19.07.30.06; Mon, 19 Sep 2022 07:30:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229745AbiISO3g (ORCPT + 99 others); Mon, 19 Sep 2022 10:29:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229656AbiISO3f (ORCPT ); Mon, 19 Sep 2022 10:29:35 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB403DE3; Mon, 19 Sep 2022 07:29:33 -0700 (PDT) Received: from canpemm500010.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MWRnc5Ft1zpSyy; Mon, 19 Sep 2022 22:26:44 +0800 (CST) Received: from huawei.com (10.175.127.227) by canpemm500010.china.huawei.com (7.192.105.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 19 Sep 2022 22:29:31 +0800 From: Ye Bin To: , , CC: , , Ye Bin Subject: [PATCH -next 1/2] ext4: fix potential memory leak in ext4_fc_record_regions() Date: Mon, 19 Sep 2022 22:40:20 +0800 Message-ID: <20220919144021.2162295-2-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220919144021.2162295-1-yebin10@huawei.com> References: <20220919144021.2162295-1-yebin10@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500010.china.huawei.com (7.192.105.118) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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-ext4@vger.kernel.org As krealloc may return NULL, in this case 'state->fc_regions' may not be freed by krealloc, but 'state->fc_regions' already set NULL. Then will lead to 'state->fc_regions' memory leak. Signed-off-by: Ye Bin --- fs/ext4/fast_commit.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index 9217a588afd1..cc8c8db075ba 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -1677,15 +1677,17 @@ int ext4_fc_record_regions(struct super_block *sb, int ino, if (replay && state->fc_regions_used != state->fc_regions_valid) state->fc_regions_used = state->fc_regions_valid; if (state->fc_regions_used == state->fc_regions_size) { + struct ext4_fc_alloc_region *fc_regions; + state->fc_regions_size += EXT4_FC_REPLAY_REALLOC_INCREMENT; - state->fc_regions = krealloc( - state->fc_regions, - state->fc_regions_size * - sizeof(struct ext4_fc_alloc_region), - GFP_KERNEL); - if (!state->fc_regions) + fc_regions = krealloc(state->fc_regions, + state->fc_regions_size * + sizeof(struct ext4_fc_alloc_region), + GFP_KERNEL); + if (!fc_regions) return -ENOMEM; + state->fc_regions = fc_regions; } region = &state->fc_regions[state->fc_regions_used++]; region->ino = ino; -- 2.31.1