Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a4db5fe5 authored by J. Bruce Fields's avatar J. Bruce Fields Committed by Linus Torvalds
Browse files

[PATCH] knfsd: nfsd4: fix memory leak on kmalloc failure in savemem



The wrong pointer is being kfree'd in savemem() when defer_free returns with
an error.

Signed-off-by: default avatarBenny Halevy <bhalevy@panasas.com>
Signed-off-by: default avatarJ. Bruce Fields <bfields@citi.umich.edu>
Signed-off-by: default avatarNeil Brown <neilb@suse.de>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 28e05dd8
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -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)
{