diff options
| author | Mike Pall <mike> | 2013-01-28 12:29:31 +0100 |
|---|---|---|
| committer | Mike Pall <mike> | 2013-01-28 12:29:31 +0100 |
| commit | a3db8f3562d2e522b845cd1ee536f4a54a443ca6 (patch) | |
| tree | 79fcb651755ca05078d32f5216658391b90dfbdc /src | |
| parent | 1651684417e3839d757f034fefea55fba7494ab2 (diff) | |
| download | luajit-a3db8f3562d2e522b845cd1ee536f4a54a443ca6.tar.gz luajit-a3db8f3562d2e522b845cd1ee536f4a54a443ca6.tar.bz2 luajit-a3db8f3562d2e522b845cd1ee536f4a54a443ca6.zip | |
Avoid leaking memory on kernels with recalcitrant mmap() behavior.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lj_mcode.c | 15 |
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) | |||
| 99 | static void *mcode_alloc_at(jit_State *J, uintptr_t hint, size_t sz, int prot) | 99 | static void *mcode_alloc_at(jit_State *J, uintptr_t hint, size_t sz, int prot) |
| 100 | { | 100 | { |
| 101 | void *p = mmap((void *)hint, sz, prot, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); | 101 | void *p = mmap((void *)hint, sz, prot, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); |
| 102 | if (p == MAP_FAILED && !hint) | 102 | if (p == MAP_FAILED) { |
| 103 | lj_trace_err(J, LJ_TRERR_MCODEAL); | 103 | if (!hint) lj_trace_err(J, LJ_TRERR_MCODEAL); |
| 104 | p = NULL; | ||
| 105 | } | ||
| 104 | return p; | 106 | return p; |
| 105 | } | 107 | } |
| 106 | 108 | ||
| @@ -220,11 +222,10 @@ static void *mcode_alloc(jit_State *J, size_t sz) | |||
| 220 | if (mcode_validptr(hint)) { | 222 | if (mcode_validptr(hint)) { |
| 221 | void *p = mcode_alloc_at(J, hint, sz, MCPROT_GEN); | 223 | void *p = mcode_alloc_at(J, hint, sz, MCPROT_GEN); |
| 222 | 224 | ||
| 223 | if (mcode_validptr(p)) { | 225 | if (mcode_validptr(p) && |
| 224 | if ((uintptr_t)p + sz - target < range || target - (uintptr_t)p < range) | 226 | ((uintptr_t)p + sz - target < range || target - (uintptr_t)p < range)) |
| 225 | return p; | 227 | return p; |
| 226 | mcode_free(J, p, sz); /* Free badly placed area. */ | 228 | if (p) mcode_free(J, p, sz); /* Free badly placed area. */ |
| 227 | } | ||
| 228 | } | 229 | } |
| 229 | /* Next try probing pseudo-random addresses. */ | 230 | /* Next try probing pseudo-random addresses. */ |
| 230 | do { | 231 | do { |
