File tree Expand file tree Collapse file tree 1 file changed +4
-1
lines changed Expand file tree Collapse file tree 1 file changed +4
-1
lines changed Original file line number Diff line number Diff line change @@ -53,18 +53,19 @@ pub const FileFinder = struct {
53
53
/// Find a file and automatically look in the parent directory if it is not found.
54
54
fn recursiveFind(allocator: std.mem.Allocator, dirname: []const u8, filename: []const u8) ![]const u8 {
55
55
const path = try std.fs.path.join(allocator, &.{ dirname, filename });
56
- errdefer allocator.free(path);
57
56
58
57
const f = std.fs.openFileAbsolute(path, .{}) catch |e| {
59
58
// Find the file, but could not open it.
60
59
if (e != std.fs.File.OpenError.FileNotFound) {
60
+ allocator.free(path);
61
61
return e;
62
62
} else {
63
63
// Not Found, try the parent dir
64
64
if (std.fs.path.dirname(dirname)) |parent| {
65
65
allocator.free(path); // situation not captured by errdefer
66
66
return Self.recursiveFind(allocator, parent, filename);
67
67
} else {
68
+ allocator.free(path);
68
69
return std.fs.File.OpenError.FileNotFound;
69
70
}
70
71
}
@@ -78,8 +79,10 @@ pub const FileFinder = struct {
78
79
}
79
80
80
81
if (std.fs.path.dirname(dirname)) |parent| {
82
+ allocator.free(path);
81
83
return Self.recursiveFind(allocator, parent, filename);
82
84
} else {
85
+ allocator.free(path);
83
86
return std.fs.File.OpenError.FileNotFound;
84
87
}
85
88
}
You can’t perform that action at this time.
0 commit comments