refactor: improve create pattern to avoid leaks

This commit is contained in:
CJ van den Berg 2025-07-19 00:03:30 +02:00
parent eb2ac10d05
commit b885fc6602
3 changed files with 7 additions and 1 deletions

View file

@ -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,