Skip to content

Commit 017b970

Browse files
authored
fix memory leak again (#11)
Close: #9
1 parent 0bbb7e7 commit 017b970

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/utils.zig

+4-1
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,19 @@ pub const FileFinder = struct {
5353
/// Find a file and automatically look in the parent directory if it is not found.
5454
fn recursiveFind(allocator: std.mem.Allocator, dirname: []const u8, filename: []const u8) ![]const u8 {
5555
const path = try std.fs.path.join(allocator, &.{ dirname, filename });
56-
errdefer allocator.free(path);
5756

5857
const f = std.fs.openFileAbsolute(path, .{}) catch |e| {
5958
// Find the file, but could not open it.
6059
if (e != std.fs.File.OpenError.FileNotFound) {
60+
allocator.free(path);
6161
return e;
6262
} else {
6363
// Not Found, try the parent dir
6464
if (std.fs.path.dirname(dirname)) |parent| {
6565
allocator.free(path); // situation not captured by errdefer
6666
return Self.recursiveFind(allocator, parent, filename);
6767
} else {
68+
allocator.free(path);
6869
return std.fs.File.OpenError.FileNotFound;
6970
}
7071
}
@@ -78,8 +79,10 @@ pub const FileFinder = struct {
7879
}
7980

8081
if (std.fs.path.dirname(dirname)) |parent| {
82+
allocator.free(path);
8183
return Self.recursiveFind(allocator, parent, filename);
8284
} else {
85+
allocator.free(path);
8386
return std.fs.File.OpenError.FileNotFound;
8487
}
8588
}

0 commit comments

Comments
 (0)