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

@ -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);