Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp4897450rwb; Tue, 20 Sep 2022 23:32:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7YIjjDEKVOiZUgOJ1zybboVTTAp+BQSTbCoxKQVtPUOgY7/hNzEZ3qWv2SjxLczWuTC4Q4 X-Received: by 2002:a63:1a1f:0:b0:438:d11b:e23d with SMTP id a31-20020a631a1f000000b00438d11be23dmr22637444pga.335.1663741957595; Tue, 20 Sep 2022 23:32:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663741957; cv=none; d=google.com; s=arc-20160816; b=UBcw+0dvtsWN7jk+Hjk41UvOLx4zZAbs7CiFzyJ5l4jN1vSJzim1GRqH+oAVKVRDhh zOTYieWiRT6yooir3zdFF4LcAaz8w9wuuMl/5qygLORacxF5bqqqTrBNto2CHBl9TmY1 qJ4KdcudST5HEMrDOxSi6MmgiACfah2UtKnL7dV2a5Z7iZ4Wy3KiboOHT2ImamO0IQC6 QvoEoCA8kLGTgbObVkH/BLet9shSQdKxFcISkE7iXGBjngOFQLvDCKEx9xuRGjriTf8g LiGqYTZyb3n4/bcjoqOPhTOdSWZGfOZo43mSSHeAwzMvxpG0ytkBxwSvu9NcEs8Ln2C4 g4ug== 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=301OxmYwJFHK2DyO/oFgAhzvTdMnnQp/nMkN4OQGFUU=; b=DqG2yfxoAqFyHYhRLox6byJz3es8Qb+k7WWJpnFVDxzp/y5ExopFnTdNBCeQ44bqyA RoKVODAlUuu1LSfBEx84Oh12sBJYMELgg1GAarzBgaoeCKBf/P+o2ijyZSL3loSgaHlI m+9gJyfeqDKRJNJMHp2LpPpTlpwiK5mkkY0Y25PQr5xu4yZn7bQ945o1qy34a8SLc0iZ eZadW9cCjGC0Hko1nOIfbiwiIN+5MByDRQZtqdpNaC2fxdbWeB+lof/E/S/SI7XbLPLe Fc9AAu2Jny1IaFHvjP8hP3QfTsMWaLAMMxlh2dZZIjjKZzfT1NXqS189mBulsz026Y6J hk/Q== 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 b8-20020a17090acc0800b001f524e93cfasi1677063pju.184.2022.09.20.23.32.24; Tue, 20 Sep 2022 23:32:37 -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 S229884AbiIUG36 (ORCPT + 99 others); Wed, 21 Sep 2022 02:29:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229666AbiIUG34 (ORCPT ); Wed, 21 Sep 2022 02:29:56 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87FFB15A18; Tue, 20 Sep 2022 23:29:54 -0700 (PDT) Received: from canpemm500010.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MXT131npDzMnsf; Wed, 21 Sep 2022 14:25:11 +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; Wed, 21 Sep 2022 14:29:52 +0800 From: Ye Bin To: , , CC: , , Ye Bin Subject: [PATCH -next v2 2/3] ext4: fix potential memory leak in ext4_fc_record_regions() Date: Wed, 21 Sep 2022 14:40:39 +0800 Message-ID: <20220921064040.3693255-3-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220921064040.3693255-1-yebin10@huawei.com> References: <20220921064040.3693255-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: dggems706-chm.china.huawei.com (10.3.19.183) 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 29a22ee0adb8..f5b0fc50ed47 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -1679,15 +1679,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