ref: 216975cab68aaa631ae92b467614465cb42bca10
parent: 8e7e353e186fd97f86feef8307e04f2032129ada
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)
;;
}