From dd4e9fb16b17579de1b54cdea90df82e41a50340 Mon Sep 17 00:00:00 2001 From: Sebastian Keller Date: Wed, 6 Nov 2019 01:42:07 +0100 Subject: [PATCH] Fixed a leak in the json parser. parseString() created a copy of the string using the wrong allocator. Instead of using the ArenaAllocator, it was using the allocator passed into Parser.init(). This lead to a leak as the copied string was not freed when the ArenaAllocator was deinited. --- lib/std/json.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/std/json.zig b/lib/std/json.zig index f385205a2..e126f103a 100644 --- a/lib/std/json.zig +++ b/lib/std/json.zig @@ -898,7 +898,7 @@ pub const TokenStream = struct { } } - if(self.parser.complete){ + if (self.parser.complete) { return null; } else { return error.UnexpectedEndOfJson; @@ -1339,7 +1339,7 @@ pub const Parser = struct { // TODO: We don't strictly have to copy values which do not contain any escape // characters if flagged with the option. const slice = token.slice(input, i); - return Value{ .String = try mem.dupe(p.allocator, u8, slice) }; + return Value{ .String = try mem.dupe(allocator, u8, slice) }; } fn parseNumber(p: *Parser, token: Token, input: []const u8, i: usize) !Value {