aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/root.zig
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-01-31 15:31:15 +0900
committernsfisis <nsfisis@gmail.com>2026-01-31 15:47:23 +0900
commit617ddc62aa4d3153850362526069b85bfaf5e59e (patch)
tree6940c577bbecdbf7856ef3c37ab43b256d33da59 /src/root.zig
parent6be43138338fbe4623c1cd62cf71138873af3a7a (diff)
downloadzgjq-617ddc62aa4d3153850362526069b85bfaf5e59e.tar.gz
zgjq-617ddc62aa4d3153850362526069b85bfaf5e59e.tar.zst
zgjq-617ddc62aa4d3153850362526069b85bfaf5e59e.zip
use reference counting to manage JSON value lifetime
Diffstat (limited to 'src/root.zig')
-rw-r--r--src/root.zig2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/root.zig b/src/root.zig
index e61ed1f..e2152d3 100644
--- a/src/root.zig
+++ b/src/root.zig
@@ -12,6 +12,7 @@ pub fn run(allocator: std.mem.Allocator, input: []const u8, query: []const u8) !
try runtime.compileFromSlice(query);
try runtime.start(json);
const result = try runtime.next() orelse return error.NoResult;
+ defer result.deinit(allocator);
const output = try jv.stringify(allocator, result);
return output;
}
@@ -34,6 +35,7 @@ fn testRunMultiple(expected: []const []const u8, input: []const u8, query: []con
for (expected) |ex| {
const result_value = try runtime.next() orelse return error.NoResult;
+ defer result_value.deinit(allocator);
const result = try jv.stringify(allocator, result_value);
defer allocator.free(result);
try std.testing.expectEqualStrings(ex, result);