[PATCH 3/3] Fix memory leak of do_mbind()

From: KOSAKI Motohiro
Date: Thu Oct 08 2009 - 21:10:08 EST


If migrate_prep is failed, new variable is leaked.
This patch fixes it.

Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@xxxxxxxxxxxxxx>
---
mm/mempolicy.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 824abf3..38ce2a7 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -1027,7 +1027,7 @@ static long do_mbind(unsigned long start, unsigned long len,

err = migrate_prep();
if (err)
- return err;
+ goto mpol_out;
}
{
NODEMASK_SCRATCH(scratch);
@@ -1042,10 +1042,9 @@ static long do_mbind(unsigned long start, unsigned long len,
err = -ENOMEM;
NODEMASK_SCRATCH_FREE(scratch);
}
- if (err) {
- mpol_put(new);
- return err;
- }
+ if (err)
+ goto mpol_out;
+
vma = check_range(mm, start, end, nmask,
flags | MPOL_MF_INVERT, &pagelist);

@@ -1066,6 +1065,7 @@ static long do_mbind(unsigned long start, unsigned long len,
}

up_write(&mm->mmap_sem);
+ mpol_out:
mpol_put(new);
return err;
}
--
1.6.0.GIT



--
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/