shithub: mc

Download patch

ref: 5b36d5c8a69402c36d272e0edbbc24c50bf5e1dc
parent: bfa11fcba69ea0c01465806c96a55af3fdeb31cd
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Jan 3 12:59:58 EST 2015

Don't leak memory in the allocator.

    Just address space. Oy.

--- a/libstd/alloc.myr
+++ b/libstd/alloc.myr
@@ -340,7 +340,11 @@
 		s.next = bkt.slabs
 		bkt.slabs = s
 	elif s.nfree == bkt.nper
-		if bkt.ncache < Cachemax
+		/*
+		HACK HACK HACK: if we can't unmap, keep an infinite cache per slab size.
+		We should solve this better somehow.
+		*/
+		if bkt.ncache < Cachemax || !Canunmap
 			s.next = bkt.cache
 			bkt.cache = s
 		else
--- a/libstd/syswrap+plan9.myr
+++ b/libstd/syswrap+plan9.myr
@@ -63,6 +63,7 @@
 	const exit	: (status:int -> void)
 	const waitpid	: (pid:pid, loc:int32#, opt : int64	-> pid)
 
+	pkglocal const Canunmap	: bool = true
 	pkglocal const getmem	: (sz : size -> byte#)
 	pkglocal const freemem	: (p : byte#, sz : size -> void)
 	pkglocal const curtime	: (-> time)
@@ -202,7 +203,8 @@
 }
 	
 const freemem = {p, sz
-	/* FIXME: don't leak */
+	/* FIXME: we leak address space */
+	sys.segfree(p, sz)
 }
 
 const curtime = {
@@ -235,4 +237,4 @@
 		| ((buf[5] castto(int32)) << 40) \
 		| ((buf[6] castto(int32)) << 48) \
 		| ((buf[7] castto(int32)) << 56)
-}
\ No newline at end of file
+}
--- a/libstd/syswrap+posixy.myr
+++ b/libstd/syswrap+posixy.myr
@@ -64,6 +64,7 @@
 	const exit	: (status:int -> void)
 	const waitpid	: (pid:pid, loc:int32#, opt : int64	-> int64)
 
+	pkglocal const Canunmap	: bool = true
 	pkglocal const getmem	: (sz : size -> byte#)
 	pkglocal const freemem	: (p : byte#, sz : size -> void)
 	pkglocal const curtime	: (-> time)