diff --git a/src/result.zig b/src/result.zig index 2e65e96..654ff09 100644 --- a/src/result.zig +++ b/src/result.zig @@ -131,6 +131,7 @@ pub fn ResultMapper(comptime Model: type, comptime TableShape: type, comptime Me // Create an arena for mapper data. var mapperArena = std.heap.ArenaAllocator.init(allocator); + errdefer mapperArena.deinit(); // Initialize query result reader. const reader = try queryReader.init(mapperArena.allocator()); @@ -166,6 +167,13 @@ pub fn ResultMapper(comptime Model: type, comptime TableShape: type, comptime Me try models.append(model); } + errdefer { + // Destroy models when something bad happen. + for (models.items) |model| { + allocator.destroy(model); + } + } + if (relations) |relationsToLoad| { inline for (relationsToLoad) |relation| { // Build query for the relation to get.