close handles while making temporary paths

This commit is contained in:
Luna 2020-06-02 16:11:30 -03:00
parent d6c92c0231
commit 0240b10a3c

View file

@ -95,12 +95,16 @@ pub fn temporaryName(allocator: *std.mem.Allocator) ![]u8 {
} }
// if we fail to access it, we assume it doesn't exist and return it. // if we fail to access it, we assume it doesn't exist and return it.
var tmp_file: std.fs.File = std.fs.cwd().openFile(
_ = std.fs.cwd().openFile(nam, .{ .read = true, .write = false }) catch |err| { nam,
if (err == error.FileNotFound) { .{ .read = true, .write = false },
return nam; ) catch |err| blk: {
} if (err == error.FileNotFound) return nam else continue;
}; };
// if we actually found someone, close the handle so that we don't
// get EMFILE later on.
tmp_file.close();
} }
return error.TempGenFail; return error.TempGenFail;