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
|
|
@ -285,6 +285,7 @@ pub const DeserializeError = error{
|
|||
|
||||
pub fn fromCbor(cb: []const u8, allocator: std.mem.Allocator) DeserializeError!struct { *TSQuery, *std.heap.ArenaAllocator } {
|
||||
var arena = try allocator.create(std.heap.ArenaAllocator);
|
||||
errdefer allocator.destroy(arena);
|
||||
arena.* = std.heap.ArenaAllocator.init(allocator);
|
||||
errdefer arena.deinit();
|
||||
const query = try arena.allocator().create(TSQuery);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue