Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp4438939ybl; Tue, 20 Aug 2019 11:55:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqx/sWvxQxIqpxXx5cyjfNuAH9uync8yMHYZtGiZR3z0yvpKtTR7XUAHtrlbpW78SVf+dAnm X-Received: by 2002:a17:90a:2764:: with SMTP id o91mr1412002pje.57.1566327337971; Tue, 20 Aug 2019 11:55:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566327337; cv=none; d=google.com; s=arc-20160816; b=R0YUe0sCo4Es0V10BSRK6ZR0MPVfGS9FcQVMxggyws0s7bcUYTr8Rjat+uacvcxZyO /3yM2Czto42DObbNxIwQmaOnORgw4BCAYcASSqUT+2HEdoExhVnUuaHARzW0C4GtOhQt U0FBpXcb+l3ZkzXVCB+TGou+4az0A2zjGIHyrK0H2jbJ4AVgxumtU/UVzDrcp0rRunJT YHULQ5lOc16p90MHZb6FftE7ZXRanunNnbEwrllcYEdbA7bC0+WIG7Cus0gz1Rnh7gtR f/8NFbaCK/Z099feqIPuobh0levLfddj3twl252tZCIbM9ngDn2aHDsH2uL0vCoq2FNQ fOYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=lsB9snO0qX4litakwfhl6CbLP+X1LCx/hTmjIzqnnDw=; b=kII7YDQ5SP7bmJErvdIc4LWDrQ9PHdXvqVefKKT3RszOYq3rB3YSziDE5gfFBnKLS/ p9pvEq2nvUhjvklIEH0036RTEbHjL6/RlMfWA9LFu/3vLzJpftCN5JXbMPnk9RXY4c5R Sv+Fkx780Vq2Mibd0wR3KRpbc28zWXNm2J6wgnUzughXlDqnDNK011gBum9jEHJdhdiL c8V3L1Z2rSS8LZn9a/SPZwK6E2+Dl2k1IQhzqpK2dV/g3G7QDR6zQo4hHVl3N/mCpdnP wuWTS2zOzbGGnzpyq8haEf/pL2qsuJ0VxPyguB2rNV1NF56tvgA9Z10JKw2b0I6ozezN gzGw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o7si12370014pgv.247.2019.08.20.11.55.20; Tue, 20 Aug 2019 11:55:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730273AbfHTSy1 (ORCPT + 99 others); Tue, 20 Aug 2019 14:54:27 -0400 Received: from ajax.cs.uga.edu ([128.192.4.6]:39850 "EHLO ajax.cs.uga.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728185AbfHTSy1 (ORCPT ); Tue, 20 Aug 2019 14:54:27 -0400 Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (authenticated bits=0) by ajax.cs.uga.edu (8.14.4/8.14.4) with ESMTP id x7KIsOnE056106 (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 20 Aug 2019 14:54:25 -0400 Received: by mail-lf1-f53.google.com with SMTP id j17so4937319lfp.3; Tue, 20 Aug 2019 11:54:25 -0700 (PDT) X-Gm-Message-State: APjAAAXDVqMnMY/VUh71YC9MAaUg3v+AsPdC8apTM/AoGtHxZacks+UQ 1r0+44WcqBPQCCQn8aUMpKWfS/QpBCPpuE1T1OY= X-Received: by 2002:a19:4c88:: with SMTP id z130mr16540511lfa.149.1566327263894; Tue, 20 Aug 2019 11:54:23 -0700 (PDT) MIME-Version: 1.0 References: <1566287651-11386-1-git-send-email-wenwen@cs.uga.edu> In-Reply-To: From: Wenwen Wang Date: Tue, 20 Aug 2019 14:53:47 -0400 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] NFSv4: Fix a memory leak bug To: "Schumaker, Anna" Cc: "linux-nfs@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "trond.myklebust@hammerspace.com" , Wenwen Wang Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 20, 2019 at 9:41 AM Schumaker, Anna wrote: > > Hi Wenwen, > > On Tue, 2019-08-20 at 02:54 -0500, Wenwen Wang wrote: > > In nfs4_try_migration(), if nfs4_begin_drain_session() fails, the > > previously allocated 'page' and 'locations' are not deallocated, > > leading to > > memory leaks. To fix this issue, free 'page' and 'locations' before > > returning the error. > > > > Signed-off-by: Wenwen Wang > > --- > > fs/nfs/nfs4state.c | 6 +++++- > > 1 file changed, 5 insertions(+), 1 deletion(-) > > > > diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c > > index cad4e06..37823dc 100644 > > --- a/fs/nfs/nfs4state.c > > +++ b/fs/nfs/nfs4state.c > > @@ -2095,8 +2095,12 @@ static int nfs4_try_migration(struct > > nfs_server *server, const struct cred *cred > > } > > > > status = nfs4_begin_drain_session(clp); > > - if (status != 0) > > + if (status != 0) { > > + if (page != NULL) > > + __free_page(page); > > + kfree(locations); > > return status; > > Thanks for the suggestion! I think a better option would be to switch > the "return status" into a "goto out" so we can keep all our cleanup > code in a single place in case we ever need to change it in the future. > > What do you think? Thanks for your comments! I will rework the patch. Wenwen > Anna > > > + } > > > > status = nfs4_replace_transport(server, locations); > > if (status != 0) { > > -- > > 2.7.4 > >