Problem
In the mmap_overlay branch of AnyTrigramIndex.candidates, a result ArrayList is created with ensureTotalCapacity. If toOwnedSlice fails (OOM), the ArrayList's backing buffer is not freed — there is no defer result.deinit(allocator) before the break :blk null fallback:
// src/index.zig — AnyTrigramIndex.candidates, mmap_overlay branch
var result: std.ArrayList([]const u8) = .{};
result.ensureTotalCapacity(allocator, merged.count()) catch break :blk null;
while (it.next()) |k| result.appendAssumeCapacity(k.*);
break :blk result.toOwnedSlice(allocator) catch null; // ← leaks result.items on OOM
The leak is proportional to merged.count() (can be large for common trigrams) and accumulates on every search under memory pressure.
Fix
Add defer result.deinit(allocator); before the ensureTotalCapacity line, and replace catch null with a proper errdefer or restructure to only call toOwnedSlice when allocation is guaranteed to succeed.
Problem
In the
mmap_overlaybranch ofAnyTrigramIndex.candidates, aresultArrayList is created withensureTotalCapacity. IftoOwnedSlicefails (OOM), the ArrayList's backing buffer is not freed — there is nodefer result.deinit(allocator)before thebreak :blk nullfallback:The leak is proportional to
merged.count()(can be large for common trigrams) and accumulates on every search under memory pressure.Fix
Add
defer result.deinit(allocator);before theensureTotalCapacityline, and replacecatch nullwith a propererrdeferor restructure to only calltoOwnedSlicewhen allocation is guaranteed to succeed.