From patchwork Mon Aug 1 13:13:18 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Theodore Ts'o X-Patchwork-Id: 107733 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 74F71B702E for ; Mon, 1 Aug 2011 23:13:30 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751841Ab1HANN2 (ORCPT ); Mon, 1 Aug 2011 09:13:28 -0400 Received: from li9-11.members.linode.com ([67.18.176.11]:40457 "EHLO test.thunk.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751995Ab1HANN0 (ORCPT ); Mon, 1 Aug 2011 09:13:26 -0400 Received: from root (helo=tytso-glaptop) by test.thunk.org with local-esmtp (Exim 4.69) (envelope-from ) id 1QnsJ7-0003mQ-EF; Mon, 01 Aug 2011 13:13:21 +0000 Received: from tytso by tytso-glaptop with local (Exim 4.71) (envelope-from ) id 1QnsJ5-0003Ft-QX; Mon, 01 Aug 2011 09:13:19 -0400 From: Theodore Ts'o To: Ext4 Developers List Cc: Yu Jian , Andreas Dilger , "Theodore Ts'o" Subject: [PATCH 5/5] ext4: prevent memory leaks from ext4_mb_init_backend() on error path Date: Mon, 1 Aug 2011 09:13:18 -0400 Message-Id: <1312204398-12460-6-git-send-email-tytso@mit.edu> X-Mailer: git-send-email 1.7.4.1.22.gec8e1.dirty In-Reply-To: <1312204398-12460-1-git-send-email-tytso@mit.edu> References: <1312204398-12460-1-git-send-email-tytso@mit.edu> X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: tytso@thunk.org X-SA-Exim-Scanned: No (on test.thunk.org); SAEximRunCond expanded to false Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Yu Jian In ext4_mb_init(), if the s_locality_group allocation fails it will currently cause the allocations made in ext4_mb_init_backend() to be leaked. Moving the ext4_mb_init_backend() allocation after the s_locality_group allocation avoids that problem. Signed-off-by: Yu Jian Signed-off-by: Andreas Dilger Signed-off-by: "Theodore Ts'o" --- fs/ext4/mballoc.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 8beccd8..c6c71af 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -2465,12 +2465,6 @@ int ext4_mb_init(struct super_block *sb, int needs_recovery) i++; } while (i <= sb->s_blocksize_bits + 1); - /* init file for buddy data */ - ret = ext4_mb_init_backend(sb); - if (ret != 0) { - goto out; - } - spin_lock_init(&sbi->s_md_lock); spin_lock_init(&sbi->s_bal_lock); @@ -2507,6 +2501,12 @@ int ext4_mb_init(struct super_block *sb, int needs_recovery) spin_lock_init(&lg->lg_prealloc_lock); } + /* init file for buddy data */ + ret = ext4_mb_init_backend(sb); + if (ret != 0) { + goto out; + } + if (sbi->s_proc) proc_create_data("mb_groups", S_IRUGO, sbi->s_proc, &ext4_mb_seq_groups_fops, sb);