From patchwork Fri Aug 19 15:28:08 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tao Ma X-Patchwork-Id: 110690 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 E7D69B6F71 for ; Sat, 20 Aug 2011 01:30:19 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753913Ab1HSPaS (ORCPT ); Fri, 19 Aug 2011 11:30:18 -0400 Received: from oproxy8-pub.bluehost.com ([69.89.22.20]:45781 "HELO oproxy8-pub.bluehost.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1751832Ab1HSPaR (ORCPT ); Fri, 19 Aug 2011 11:30:17 -0400 Received: (qmail 10626 invoked by uid 0); 19 Aug 2011 15:30:16 -0000 Received: from unknown (HELO box585.bluehost.com) (66.147.242.185) by oproxy8.bluehost.com with SMTP; 19 Aug 2011 15:30:16 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tao.ma; s=default; h=Message-Id:Date:Subject:To:From; bh=YGCckj8vqM2Mrkl+v8ZfBg1IAvbUEwoLev+gzADCAfU=; b=vtWpMxdaXSDJYGj36XiyeGL0QWg/KeeNYx1QH9wvyGbhNsDpv4utBv8htqUConobo7FHvqPrOK0GV6U7UfGGDJo65dJrwQtcDU7UQeppkg/es//rzZUiw+n7mOsS9rzG; Received: from [221.217.45.152] (helo=localhost.localdomain) by box585.bluehost.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.76) (envelope-from ) id 1QuR1T-0004kH-Rp for linux-ext4@vger.kernel.org; Fri, 19 Aug 2011 09:30:16 -0600 From: Tao Ma To: linux-ext4@vger.kernel.org Subject: [PATCH] ext4: Free resources in the error path of ext4_mb_init. Date: Fri, 19 Aug 2011 23:28:08 +0800 Message-Id: <1313767689-2786-1-git-send-email-tm@tao.ma> X-Mailer: git-send-email 1.7.4.1 X-Identified-User: {1390:box585.bluehost.com:colyli:tao.ma} {sentby:smtp auth 221.217.45.152 authed with tm@tao.ma} Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Tao Ma In commit 79a77c5ac, we move ext4_mb_init_backend after the allocation of s_locality_group to avoid memory leak in error path, but there are still some other error paths in ext4_mb_init that need to do the same work. So this patch adds all the error patch for ext4_mb_init. And all the pointers are reset to NULL in case the caller may double free them. Signed-off-by: Tao Ma --- fs/ext4/mballoc.c | 23 +++++++++++++++-------- 1 files changed, 15 insertions(+), 8 deletions(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 17a5a57..e7d64d8 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -2490,7 +2490,7 @@ int ext4_mb_init(struct super_block *sb, int needs_recovery) sbi->s_locality_groups = alloc_percpu(struct ext4_locality_group); if (sbi->s_locality_groups == NULL) { ret = -ENOMEM; - goto out; + goto out_free_groupinfo_slab; } for_each_possible_cpu(i) { struct ext4_locality_group *lg; @@ -2503,9 +2503,8 @@ int ext4_mb_init(struct super_block *sb, int needs_recovery) /* init file for buddy data */ ret = ext4_mb_init_backend(sb); - if (ret != 0) { - goto out; - } + if (ret != 0) + goto out_free_locality_groups; if (sbi->s_proc) proc_create_data("mb_groups", S_IRUGO, sbi->s_proc, @@ -2513,11 +2512,19 @@ int ext4_mb_init(struct super_block *sb, int needs_recovery) if (sbi->s_journal) sbi->s_journal->j_commit_callback = release_blocks_on_commit; + + return 0; + +out_free_groupinfo_slab: + ext4_groupinfo_destroy_slabs(); +out_free_locality_groups: + free_percpu(sbi->s_locality_groups); + sbi->s_locality_groups = NULL; out: - if (ret) { - kfree(sbi->s_mb_offsets); - kfree(sbi->s_mb_maxs); - } + kfree(sbi->s_mb_offsets); + sbi->s_mb_offsets = NULL; + kfree(sbi->s_mb_maxs); + sbi->s_mb_maxs = NULL; return ret; }