Skip to content

Commit

Permalink
[PATCH] knfsd: nfsd4: fix memory leak on kmalloc failure in savemem
Browse files Browse the repository at this point in the history
The wrong pointer is being kfree'd in savemem() when defer_free returns with
an error.

Signed-off-by: Benny Halevy <bhalevy@panasas.com>
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
Signed-off-by: Neil Brown <neilb@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
J. Bruce Fields authored and Linus Torvalds committed Feb 16, 2007
1 parent 28e05dd commit a4db5fe
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions fs/nfsd/nfs4xdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,24 +199,22 @@ 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;
}


static __be32
nfsd4_decode_bitmap(struct nfsd4_compoundargs *argp, u32 *bmval)
{
Expand Down

0 comments on commit a4db5fe

Please sign in to comment.