summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Pall <mike>2013-01-28 12:29:31 +0100
committerMike Pall <mike>2013-01-28 12:29:31 +0100
commita3db8f3562d2e522b845cd1ee536f4a54a443ca6 (patch)
tree79fcb651755ca05078d32f5216658391b90dfbdc
parent1651684417e3839d757f034fefea55fba7494ab2 (diff)
downloadluajit2-a3db8f3562d2e522b845cd1ee536f4a54a443ca6.tar.gz
Avoid leaking memory on kernels with recalcitrant mmap() behavior.
-rw-r--r--src/lj_mcode.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/lj_mcode.c b/src/lj_mcode.c
index 34405b5a..42a4a0bf 100644
--- a/src/lj_mcode.c
+++ b/src/lj_mcode.c
@@ -99,8 +99,10 @@ static void mcode_setprot(void *p, size_t sz, DWORD prot)
static void *mcode_alloc_at(jit_State *J, uintptr_t hint, size_t sz, int prot)
{
void *p = mmap((void *)hint, sz, prot, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
- if (p == MAP_FAILED && !hint)
- lj_trace_err(J, LJ_TRERR_MCODEAL);
+ if (p == MAP_FAILED) {
+ if (!hint) lj_trace_err(J, LJ_TRERR_MCODEAL);
+ p = NULL;
+ }
return p;
}
@@ -220,11 +222,10 @@ static void *mcode_alloc(jit_State *J, size_t sz)
if (mcode_validptr(hint)) {
void *p = mcode_alloc_at(J, hint, sz, MCPROT_GEN);
- if (mcode_validptr(p)) {
- if ((uintptr_t)p + sz - target < range || target - (uintptr_t)p < range)
- return p;
- mcode_free(J, p, sz); /* Free badly placed area. */
- }
+ if (mcode_validptr(p) &&
+ ((uintptr_t)p + sz - target < range || target - (uintptr_t)p < range))
+ return p;
+ if (p) mcode_free(J, p, sz); /* Free badly placed area. */
}
/* Next try probing pseudo-random addresses. */
do {