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 {...@@ -898,7 +898,7 @@ pub const TokenStream = struct {
898 }898 }
899 }899 }
900900
901 if(self.parser.complete){901 if (self.parser.complete) {
902 return null;902 return null;
903 } else {903 } else {
904 return error.UnexpectedEndOfJson;904 return error.UnexpectedEndOfJson;
...@@ -1339,7 +1339,7 @@ pub const Parser = struct {...@@ -1339,7 +1339,7 @@ pub const Parser = struct {
1339 // TODO: We don't strictly have to copy values which do not contain any escape1339 // TODO: We don't strictly have to copy values which do not contain any escape
1340 // characters if flagged with the option.1340 // characters if flagged with the option.
1341 const slice = token.slice(input, i);1341 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) };
1343 }1343 }
13441344
1345 fn parseNumber(p: *Parser, token: Token, input: []const u8, i: usize) !Value {1345 fn parseNumber(p: *Parser, token: Token, input: []const u8, i: usize) !Value {