hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 577e39d694db9c6b40760293eb5574322e93bb7d
parent edafe4a69721d48ca71312681bf8feb70880ec32
Author: Drew DeVault <sir@cmpwn.com>
Date:   Mon,  4 Apr 2022 12:12:47 +0200

os+freebsd: fix iter

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Mos/+freebsd/dirfdfs.ha | 11++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/os/+freebsd/dirfdfs.ha b/os/+freebsd/dirfdfs.ha @@ -364,6 +364,7 @@ fn fs_iter(fs: *fs::fs, path: str) (*fs::iterator | fs::error) = { let iter = alloc(os_iterator { iter = fs::iterator { next = &iter_next, + finish = &iter_finish, }, fd = fd, buf = buf[..fs.getdents_bufsz], @@ -378,9 +379,6 @@ fn iter_next(iter: *fs::iterator) (fs::dirent | void) = { let n = rt::getdents(iter.fd, iter.buf: *[*]u8, len(iter.buf)) as size; if (n == 0) { - rt::close(iter.fd)!; - free(iter.buf); - free(iter); return; }; iter.buf_end = n; @@ -415,3 +413,10 @@ fn iter_next(iter: *fs::iterator) (fs::dirent | void) = { ftype = ftype, }; }; + +fn iter_finish(iter: *fs::iterator) void = { + let iter = iter: *os_iterator; + rt::close(iter.fd)!; + free(iter.buf); + free(iter); +};