ref: 1397150d077b13445250c0470e2a96052523c0b7
parent: b040d8ccff7557ea1a33428020ae1c484081eab6
author: Andrew Chambers <andrewchamberss@gmail.com>
date: Sun Jan 17 16:07:56 EST 2016
fixes to mktemp - fix memory leak on error condition - fix double /tmp/
--- a/lib/std/mktemp.myr
+++ b/lib/std/mktemp.myr
@@ -20,7 +20,7 @@
const Retries = 100
const mktemp = {base, opt, mode
- var tmpdir, path, uniq
+ var tmpdir, path
match std.getenv("TMPDIR")
| `std.Some d: tmpdir = d
@@ -28,21 +28,18 @@
;;
for var i = 0; i < Retries; i++
- uniq = randpath(tmpdir, base)
- path = pathcat(tmpdir, uniq)
+ path = randpath(tmpdir, base)
match std.openmode(path, opt | Ocreat, mode)
| `Fail e:
if e != Eexist
- std.slfree(uniq)
+ std.slfree(path)
std.slfree(tmpdir)
-> `Fail e
;;
| `Ok fd:
- std.slfree(uniq)
std.slfree(tmpdir)
-> `Ok (fd, path)
;;
- std.slfree(uniq)
std.slfree(path)
;;
std.slfree(tmpdir)