[PATCH] iSeries: Don't leak if allocations fail inmf_getSrcHistory

From: Jesper Juhl
Date: Sat Oct 30 2010 - 13:31:26 EST


Hi,

If memory is tight and a dynamic allocation fails there's no reason to
make a bad situation worse by leaking memory.

mf_getSrcHistory potentially leaks pages[0-3]. I believe the right thing
to do is to free that memory again before returning -ENOMEM - which is
what this patch does.

I realize that the function is under '#if 0' so this probably doesn't
matter much, but I assume that the function is still there for a reason
(but I could be wrong, I don't know the powerpc code).
Anyway, I suggest we remove the leak.

Please keep me on CC when replying.


Signed-off-by: Jesper Juhl <jj@xxxxxxxxxxxxx>
---
mf.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/platforms/iseries/mf.c b/arch/powerpc/platforms/iseries/mf.c
index 42d0a88..f67522a 100644
--- a/arch/powerpc/platforms/iseries/mf.c
+++ b/arch/powerpc/platforms/iseries/mf.c
@@ -1058,8 +1058,13 @@ static void mf_getSrcHistory(char *buffer, int size)
pages[2] = kmalloc(4096, GFP_ATOMIC);
pages[3] = kmalloc(4096, GFP_ATOMIC);
if ((ev == NULL) || (pages[0] == NULL) || (pages[1] == NULL)
- || (pages[2] == NULL) || (pages[3] == NULL))
+ || (pages[2] == NULL) || (pages[3] == NULL)) {
+ kfree(pages[3]);
+ kfree(pages[2]);
+ kfree(pages[1]);
+ kfree(pages[0]);
return -ENOMEM;
+ }

return_stuff.xType = 0;
return_stuff.xRc = 0;


--
Jesper Juhl <jj@xxxxxxxxxxxxx> http://www.chaosbits.net/
Plain text mails only, please http://www.expita.com/nomime.html
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/