* [PATCH] NFSv4: Fix a memory leak bug
@ 2019-08-20 7:54 Wenwen Wang
2019-08-20 13:41 ` Schumaker, Anna
0 siblings, 1 reply; 3+ messages in thread
From: Wenwen Wang @ 2019-08-20 7:54 UTC (permalink / raw)
To: Wenwen Wang
Cc: Trond Myklebust, Anna Schumaker, open list:NFS, SUNRPC,
AND LOCKD CLIENTS, open list
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 <wenwen@cs.uga.edu>
---
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;
+ }
status = nfs4_replace_transport(server, locations);
if (status != 0) {
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] NFSv4: Fix a memory leak bug
2019-08-20 7:54 [PATCH] NFSv4: Fix a memory leak bug Wenwen Wang
@ 2019-08-20 13:41 ` Schumaker, Anna
2019-08-20 18:53 ` Wenwen Wang
0 siblings, 1 reply; 3+ messages in thread
From: Schumaker, Anna @ 2019-08-20 13:41 UTC (permalink / raw)
To: wenwen; +Cc: linux-nfs, linux-kernel, trond.myklebust
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 <wenwen@cs.uga.edu>
> ---
> 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?
Anna
> + }
>
> status = nfs4_replace_transport(server, locations);
> if (status != 0) {
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] NFSv4: Fix a memory leak bug
2019-08-20 13:41 ` Schumaker, Anna
@ 2019-08-20 18:53 ` Wenwen Wang
0 siblings, 0 replies; 3+ messages in thread
From: Wenwen Wang @ 2019-08-20 18:53 UTC (permalink / raw)
To: Schumaker, Anna; +Cc: linux-nfs, linux-kernel, trond.myklebust, Wenwen Wang
On Tue, Aug 20, 2019 at 9:41 AM Schumaker, Anna
<Anna.Schumaker@netapp.com> 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 <wenwen@cs.uga.edu>
> > ---
> > 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
> >
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-08-20 18:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-20 7:54 [PATCH] NFSv4: Fix a memory leak bug Wenwen Wang
2019-08-20 13:41 ` Schumaker, Anna
2019-08-20 18:53 ` Wenwen Wang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.