summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2021-07-18 16:43:00 +0200
committerYorhel <git@yorhel.nl>2021-07-18 16:43:02 +0200
commitb96587c25feff6e52f0b5a5104359046c8c139d4 (patch)
tree66a135bfb317f61ed92ba452cec8bc7f1204a25c
parent6f07a369236141744792681f0c150d55abe8f72f (diff)
scan: Don't allocate directory iterator on the stack
I had planned to checkout out async functions here so I could avoid recursing onto the stack alltogether, but it's still unclear to me how to safely call into libc from async functions so let's wait for all that to get fleshed out a bit more.
-rw-r--r--src/scan.zig5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/scan.zig b/src/scan.zig
index f56c9e6..7ec36b1 100644
--- a/src/scan.zig
+++ b/src/scan.zig
@@ -449,8 +449,9 @@ var active_context: *Context = undefined;
// Read and index entries of the given dir.
fn scanDir(ctx: *Context, dir: std.fs.Dir, dir_dev: u64) void {
- // XXX: The iterator allocates 8k+ bytes on the stack, may want to do heap allocation here?
- var it = dir.iterate();
+ var it = main.allocator.create(std.fs.Dir.Iterator) catch unreachable;
+ defer main.allocator.destroy(it);
+ it.* = dir.iterate();
while(true) {
const entry = it.next() catch {
ctx.setDirlistError();