[PATCH] kfree in fs/nfsd/nfs4xdr.c:savemem()
Halevy, Benny
bhalevy at panasas.com
Sun Dec 31 15:22:41 EST 2006
J. Bruce Fields wrote:
>
> On Wed, Dec 27, 2006 at 03:18:11PM +0200, Benny Halevy wrote:
> > The wrong pointer is being kfree'd in savemem() when defer_free
> > returns with an error.
>
> Makes sense to me, thanks!
>
> That makes "new" unnecessary. Any objection to the following?
> (untested).
This seems to be right on the spot...
>
> Since this seems to be a rare memory leak, I'm inclined to leave this
> till after 2.6.20.
Agreed.
>
> --b.
>
> diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
> index dabd527..91284a0 100644
> --- a/fs/nfsd/nfs4xdr.c
> +++ b/fs/nfsd/nfs4xdr.c
> @@ -199,18 +199,16 @@ defer_free(struct nfsd4_compoundargs *argp,
>
> static char *savemem(struct nfsd4_compoundargs *argp, __be32 *p, int nbytes)
> {
> - void *new = NULL;
> if (p == argp->tmp) {
> - new = kmalloc(nbytes, GFP_KERNEL);
> - if (!new) return NULL;
> - p = new;
> + p = kmalloc(nbytes, GFP_KERNEL);
> + if (!p) return NULL;
> memcpy(p, argp->tmp, nbytes);
> } else {
> BUG_ON(p != argp->tmpp);
> argp->tmpp = NULL;
> }
> if (defer_free(argp, kfree, p)) {
> - kfree(new);
> + kfree(p);
> return NULL;
> } else
> return (char *)p;
>
More information about the NFSv4
mailing list