shithub: mc

Download patch

ref: dcee03917fb103ca72e521369053667455121a6d
parent: 871bf897b05b137adffa3b753ea490ee03ca7bf0
parent: ce9ec1e3fef7efe379448a80ef3e7a907481e903
author: Ori Bernstein <ori@eigenstate.org>
date: Wed Jan 27 18:54:45 EST 2016

Merge pull request #63 from andrewchambers/memleak

fix small memory leak

--- a/lib/std/fmt.myr
+++ b/lib/std/fmt.myr
@@ -20,6 +20,7 @@
 use "types"
 use "utf"
 use "varargs"
+use "writeall"
 
 pkg std =
 	/* write to fd */
@@ -103,7 +104,11 @@
 	sb = mksb()
 	sbfmtv(sb, fmt, ap)
 	s = sbfin(sb)
-	-> writeall(fd, s)
+	match writeall(fd, s)
+	| (n, _):
+		slfree(s)
+		-> n
+	;;
 }
 
 const fmt = {fmt, args
@@ -540,24 +545,6 @@
 		sbputc(sb, b[j - 1])
 	;;
 }
-
-const writeall = {fd, buf
-	var len
-
-	len = 0
-	while true
-		match write(fd, buf[len:])
-		| `Fail err:	break
-		| `Ok n:
-			len += n
-			if n == 0 || len == buf.len
-				break
-			;;
-		;;
-	;;
-	-> len
-}
-
 
 /* would use std.get(), but that's a dependency loop */
 const getint = {s, msg