fix: make sure we release self.snapshots_mutex on errors
This commit is contained in:
parent
505b9efeb8
commit
00140fcfe6
2 changed files with 2 additions and 0 deletions
|
|
@ -386,6 +386,7 @@ fn take_snapshot(self: *@This(), allocator: std.mem.Allocator, dir_path: []const
|
||||||
try names.append(allocator, try allocator.dupe(u8, entry.name));
|
try names.append(allocator, try allocator.dupe(u8, entry.name));
|
||||||
}
|
}
|
||||||
self.snapshots_mutex.lock();
|
self.snapshots_mutex.lock();
|
||||||
|
errdefer self.snapshots_mutex.unlock();
|
||||||
const gop = try self.snapshots.getOrPut(allocator, dir_path);
|
const gop = try self.snapshots.getOrPut(allocator, dir_path);
|
||||||
if (!gop.found_existing) gop.value_ptr.* = .empty;
|
if (!gop.found_existing) gop.value_ptr.* = .empty;
|
||||||
var snapshot = gop.value_ptr;
|
var snapshot = gop.value_ptr;
|
||||||
|
|
|
||||||
|
|
@ -331,6 +331,7 @@ fn take_snapshot(self: *@This(), allocator: std.mem.Allocator, dir_path: []const
|
||||||
var dir = std.fs.openDirAbsolute(dir_path, .{ .iterate = true }) catch return;
|
var dir = std.fs.openDirAbsolute(dir_path, .{ .iterate = true }) catch return;
|
||||||
defer dir.close();
|
defer dir.close();
|
||||||
self.snapshots_mutex.lock();
|
self.snapshots_mutex.lock();
|
||||||
|
errdefer self.snapshots_mutex.unlock();
|
||||||
const gop = try self.snapshots.getOrPut(allocator, dir_path);
|
const gop = try self.snapshots.getOrPut(allocator, dir_path);
|
||||||
if (!gop.found_existing) gop.value_ptr.* = .empty;
|
if (!gop.found_existing) gop.value_ptr.* = .empty;
|
||||||
const snapshot = gop.value_ptr;
|
const snapshot = gop.value_ptr;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue