Fix memory leaks when an error is returned while reading results.
This commit is contained in:
parent
56d9414dfa
commit
5382371954
1 changed files with 8 additions and 0 deletions
|
@ -131,6 +131,7 @@ pub fn ResultMapper(comptime Model: type, comptime TableShape: type, comptime Me
|
||||||
|
|
||||||
// Create an arena for mapper data.
|
// Create an arena for mapper data.
|
||||||
var mapperArena = std.heap.ArenaAllocator.init(allocator);
|
var mapperArena = std.heap.ArenaAllocator.init(allocator);
|
||||||
|
errdefer mapperArena.deinit();
|
||||||
|
|
||||||
// Initialize query result reader.
|
// Initialize query result reader.
|
||||||
const reader = try queryReader.init(mapperArena.allocator());
|
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);
|
try models.append(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
errdefer {
|
||||||
|
// Destroy models when something bad happen.
|
||||||
|
for (models.items) |model| {
|
||||||
|
allocator.destroy(model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (relations) |relationsToLoad| {
|
if (relations) |relationsToLoad| {
|
||||||
inline for (relationsToLoad) |relation| {
|
inline for (relationsToLoad) |relation| {
|
||||||
// Build query for the relation to get.
|
// Build query for the relation to get.
|
||||||
|
|
Loading…
Add table
Reference in a new issue