fix: json memory leaks using arena
This commit is contained in:
parent
5a8cceaa0b
commit
bc328e72ad
1 changed files with 9 additions and 7 deletions
16
src/aws.zig
16
src/aws.zig
|
@ -501,9 +501,11 @@ pub fn Request(comptime request_action: anytype) type {
|
||||||
var buf_request_id: [256]u8 = undefined;
|
var buf_request_id: [256]u8 = undefined;
|
||||||
const request_id = try requestIdFromHeaders(&buf_request_id, options.client.allocator, aws_request, response);
|
const request_id = try requestIdFromHeaders(&buf_request_id, options.client.allocator, aws_request, response);
|
||||||
|
|
||||||
|
const arena = ArenaAllocator.init(options.client.allocator);
|
||||||
|
|
||||||
if (@hasDecl(action.Response, "http_payload")) {
|
if (@hasDecl(action.Response, "http_payload")) {
|
||||||
var rc = try FullResponseType.init(.{
|
var rc = try FullResponseType.init(.{
|
||||||
.arena = ArenaAllocator.init(options.client.allocator),
|
.arena = arena,
|
||||||
.response = .{},
|
.response = .{},
|
||||||
.request_id = request_id,
|
.request_id = request_id,
|
||||||
.raw_parsed = .{ .raw = .{} },
|
.raw_parsed = .{ .raw = .{} },
|
||||||
|
@ -524,10 +526,8 @@ pub fn Request(comptime request_action: anytype) type {
|
||||||
if (std.meta.fields(action.Response).len == 0 or expected_body_field_len == 0 or response.body.len == 0) {
|
if (std.meta.fields(action.Response).len == 0 or expected_body_field_len == 0 or response.body.len == 0) {
|
||||||
// Do we care if an unexpected body comes in?
|
// Do we care if an unexpected body comes in?
|
||||||
return try FullResponseType.init(.{
|
return try FullResponseType.init(.{
|
||||||
.arena = ArenaAllocator.init(options.client.allocator),
|
.arena = arena,
|
||||||
.response = undefined,
|
|
||||||
.request_id = request_id,
|
.request_id = request_id,
|
||||||
.raw_parsed = .{ .raw = undefined },
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -538,8 +538,10 @@ pub fn Request(comptime request_action: anytype) type {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn jsonReturn(aws_request: awshttp.HttpRequest, options: Options, response: awshttp.HttpResult) !FullResponseType {
|
fn jsonReturn(aws_request: awshttp.HttpRequest, options: Options, response: awshttp.HttpResult) !FullResponseType {
|
||||||
|
var arena = ArenaAllocator.init(options.client.allocator);
|
||||||
|
|
||||||
const parser_options = json.ParseOptions{
|
const parser_options = json.ParseOptions{
|
||||||
.allocator = options.client.allocator,
|
.allocator = arena.allocator(),
|
||||||
.allow_camel_case_conversion = true, // new option
|
.allow_camel_case_conversion = true, // new option
|
||||||
.allow_snake_case_conversion = true, // new option
|
.allow_snake_case_conversion = true, // new option
|
||||||
.allow_unknown_fields = true, // new option. Cannot yet handle non-struct fields though
|
.allow_unknown_fields = true, // new option. Cannot yet handle non-struct fields though
|
||||||
|
@ -577,7 +579,7 @@ pub fn Request(comptime request_action: anytype) type {
|
||||||
const real_response = @field(parsed_response, @typeInfo(response_types.NormalResponse).@"struct".fields[0].name);
|
const real_response = @field(parsed_response, @typeInfo(response_types.NormalResponse).@"struct".fields[0].name);
|
||||||
|
|
||||||
return try FullResponseType.init(.{
|
return try FullResponseType.init(.{
|
||||||
.arena = ArenaAllocator.init(options.client.allocator),
|
.arena = arena,
|
||||||
.response = @field(real_response, @typeInfo(@TypeOf(real_response)).@"struct".fields[0].name),
|
.response = @field(real_response, @typeInfo(@TypeOf(real_response)).@"struct".fields[0].name),
|
||||||
.request_id = real_response.ResponseMetadata.RequestId,
|
.request_id = real_response.ResponseMetadata.RequestId,
|
||||||
.raw_parsed = .{ .server = parsed_response },
|
.raw_parsed = .{ .server = parsed_response },
|
||||||
|
@ -588,7 +590,7 @@ pub fn Request(comptime request_action: anytype) type {
|
||||||
const request_id = try requestIdFromHeaders(&buf_request_id, options.client.allocator, aws_request, response);
|
const request_id = try requestIdFromHeaders(&buf_request_id, options.client.allocator, aws_request, response);
|
||||||
|
|
||||||
return try FullResponseType.init(.{
|
return try FullResponseType.init(.{
|
||||||
.arena = ArenaAllocator.init(options.client.allocator),
|
.arena = arena,
|
||||||
.response = parsed_response,
|
.response = parsed_response,
|
||||||
.request_id = request_id,
|
.request_id = request_id,
|
||||||
.raw_parsed = .{ .raw = parsed_response },
|
.raw_parsed = .{ .raw = parsed_response },
|
||||||
|
|
Loading…
Add table
Reference in a new issue