refactor: improve create pattern to avoid leaks
This commit is contained in:
parent
eb2ac10d05
commit
b885fc6602
3 changed files with 7 additions and 1 deletions
|
|
@ -62,6 +62,7 @@ pub const Error = CacheError || QueryParseError || QuerySerializeError;
|
|||
|
||||
pub fn create(allocator: std.mem.Allocator, opts: struct { lock: bool = false }) !*Self {
|
||||
const self = try allocator.create(Self);
|
||||
errdefer allocator.destroy(self);
|
||||
self.* = .{
|
||||
.allocator = allocator,
|
||||
.mutex = if (opts.lock) .{} else null,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue