ref: 2281d457448549cf86ae9475627c0c12a8c4843f
parent: 03f0c0961f2350d59e9e3707ef3dac0ec196f61c
author: Ori Bernstein <[email protected]>
date: Mon Sep 15 11:03:37 EDT 2014
Check for failures in big allocations. We forgot to check for errors in the mmap() return value.
--- a/libstd/alloc.myr
+++ b/libstd/alloc.myr
@@ -211,7 +211,7 @@
/* Allocates a blob that is 'sz' bytes long. Dies if the allocation fails */
const bytealloc = {sz
- var i, bkt
+ var i, bkt, p
if !initdone
for i = 0; i < buckets.len && (Align << i) <= Bktmax; i++
@@ -222,21 +222,25 @@
if (sz <= Bktmax)
bkt = &buckets[bktnum(sz)]
- -> bktalloc(bkt)
+ p = bktalloc(bkt)
else
- -> mmap(Zbyteptr, sz, Mprotrw, Mpriv | Manon, -1, 0)
+ p = mmap(Zbyteptr, sz, Mprotrw, Mpriv | Manon, -1, 0)
+ if p == Mapbad
+ die("could not map memory\n")
+ ;;
;;
+ -> p
}
/* frees a blob that is 'sz' bytes long. */
-const bytefree = {m, sz
+const bytefree = {p, sz
var bkt
if (sz < Bktmax)
bkt = &buckets[bktnum(sz)]
- bktfree(bkt, m)
+ bktfree(bkt, p)
else
- munmap(m, sz)
+ munmap(p, sz)
;;
}