From patchwork Wed Jun 25 11:01:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinglong Mee X-Patchwork-Id: 4419521 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 5DCA29F26E for ; Wed, 25 Jun 2014 11:01:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4C778201EF for ; Wed, 25 Jun 2014 11:01:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 461D4201DD for ; Wed, 25 Jun 2014 11:01:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753217AbaFYLB3 (ORCPT ); Wed, 25 Jun 2014 07:01:29 -0400 Received: from mail-pb0-f53.google.com ([209.85.160.53]:63672 "EHLO mail-pb0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752641AbaFYLB3 (ORCPT ); Wed, 25 Jun 2014 07:01:29 -0400 Received: by mail-pb0-f53.google.com with SMTP id uo5so1569389pbc.12 for ; Wed, 25 Jun 2014 04:01:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :content-type:content-transfer-encoding; bh=mgzJ+DO+0yO5c1fHh/qyFsKJaVQJIPO0Nl2Na9W1hwk=; b=HcmfwsiL6VZXp4CmLDnl2ikztDR6jgPYuJKPHY2k1XoPdOnepPFwzE3qq2OFMCjUbP MCp5JAxL35GPee6fGa9X8doEAIusTOXb/KOKs6TS3TaiVAeidYXiEbCAOOuB7JwfPECT +rTewOr7P6lIl8L5jbO4Uv8BgziAlEtFbP04R3nxQHkl9+S1tClIgyAfVsvV4wvgZd1+ wJxPLwZD6yPqH6nDqCFXI2JlALzK6K1ZPcmK3zWoGy8Q5XGad2hFq6FG2mOAQlfxmGX3 0Q6JMUCZY6QGaM1j4sM4aHzy5omZRQkcxHop02/D0Z6jV0pClZS377M2vnP3P+hfgafV j5RQ== X-Received: by 10.66.254.166 with SMTP id aj6mr10551464pad.11.1403694088538; Wed, 25 Jun 2014 04:01:28 -0700 (PDT) Received: from [192.168.0.100] ([171.215.227.43]) by mx.google.com with ESMTPSA id fm8sm16458719pab.28.2014.06.25.04.01.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 25 Jun 2014 04:01:27 -0700 (PDT) Message-ID: <53AAABED.6080106@gmail.com> Date: Wed, 25 Jun 2014 19:01:01 +0800 From: Kinglong Mee User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: "J. Bruce Fields" CC: Linux NFS Mailing List , kinglongmee@gmail.com Subject: [PATCH 2/4] NFSD: Fix a memory leak of file if nfsd4_recdir_load failed Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Kinglong Mee --- fs/nfsd/nfs4recover.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/fs/nfsd/nfs4recover.c b/fs/nfsd/nfs4recover.c index e37ac1c..bb66037 100644 --- a/fs/nfsd/nfs4recover.c +++ b/fs/nfsd/nfs4recover.c @@ -480,6 +480,16 @@ nfsd4_init_recdir(struct net *net) return status; } +static void +nfsd4_shutdown_recdir(struct net *net) +{ + struct nfsd_net *nn = net_generic(net, nfsd_net_id); + + if (!nn->rec_file) + return; + fput(nn->rec_file); + nn->rec_file = NULL; +} static int nfs4_legacy_state_init(struct net *net) @@ -513,10 +523,13 @@ nfsd4_load_reboot_recovery_data(struct net *net) int status; status = nfsd4_init_recdir(net); - if (!status) - status = nfsd4_recdir_load(net); if (status) - printk(KERN_ERR "NFSD: Failure reading reboot recovery data\n"); + return status; + + status = nfsd4_recdir_load(net); + if (status) + nfsd4_shutdown_recdir(net); + return status; } @@ -547,21 +560,12 @@ err: } static void -nfsd4_shutdown_recdir(struct nfsd_net *nn) -{ - if (!nn->rec_file) - return; - fput(nn->rec_file); - nn->rec_file = NULL; -} - -static void nfsd4_legacy_tracking_exit(struct net *net) { struct nfsd_net *nn = net_generic(net, nfsd_net_id); nfs4_release_reclaim(nn); - nfsd4_shutdown_recdir(nn); + nfsd4_shutdown_recdir(net); nfs4_legacy_state_shutdown(net); }