authorgravatar for sebastiankeller@fastmail.netSebastian Keller <sebastiankeller@fastmail.net> 2019-11-06 01:42:07+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-06 14:00:36-05:00
logdd4e9fb16b17579de1b54cdea90df82e41a50340
treeab28bd85d288a7fb71502dc25cda1af07cb8ed75
parent6b61fcddfa16eaf24e10817390efb0180cce9c70

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.

1 files changed, 2 insertions(+), 2 deletions(-)

lib/std/json.zig+2-2
......@@ -898,7 +898,7 @@ pub const TokenStream = struct {
898898 }
899899 }
900900
901 if(self.parser.complete){
901 if (self.parser.complete) {
902902 return null;
903903 } else {
904904 return error.UnexpectedEndOfJson;
......@@ -1339,7 +1339,7 @@ pub const Parser = struct {
13391339 // TODO: We don't strictly have to copy values which do not contain any escape
13401340 // characters if flagged with the option.
13411341 const slice = token.slice(input, i);
1342 return Value{ .String = try mem.dupe(p.allocator, u8, slice) };
1342 return Value{ .String = try mem.dupe(allocator, u8, slice) };
13431343 }
13441344
13451345 fn parseNumber(p: *Parser, token: Token, input: []const u8, i: usize) !Value {