address test leaks

This commit is contained in:
Emil Lerch 2023-08-27 10:53:51 -07:00
parent 06040ac649
commit c84baf5152
Signed by: lobo
GPG Key ID: A7B62D657EF764F8
2 changed files with 4 additions and 6 deletions

View File

@ -1383,6 +1383,7 @@ fn processRequest(options: *TestOptions, server: *std.http.Server) !void {
var res = try server.accept(.{ .allocator = options.allocator }); var res = try server.accept(.{ .allocator = options.allocator });
options.server_ready = false; options.server_ready = false;
defer res.deinit(); defer res.deinit();
defer if (res.headers.owned and res.headers.list.items.len > 0) res.headers.deinit();
defer _ = res.reset(); defer _ = res.reset();
try res.wait(); // wait for client to send a complete request head try res.wait(); // wait for client to send a complete request head

View File

@ -163,7 +163,7 @@ pub const AwsHttp = struct {
defer headers.deinit(); defer headers.deinit();
for (request_cp.headers) |header| for (request_cp.headers) |header|
try headers.append(header.name, header.value); try headers.append(header.name, header.value);
log.debug("All Request Headers (zfetch):", .{}); log.debug("All Request Headers:", .{});
for (headers.list.items) |h| { for (headers.list.items) |h| {
log.debug("\t{s}: {s}", .{ h.name, h.value }); log.debug("\t{s}: {s}", .{ h.name, h.value });
} }
@ -179,6 +179,7 @@ pub const AwsHttp = struct {
const method = std.meta.stringToEnum(std.http.Method, request_cp.method).?; const method = std.meta.stringToEnum(std.http.Method, request_cp.method).?;
var req = try cl.request(method, try std.Uri.parse(url), headers, .{}); var req = try cl.request(method, try std.Uri.parse(url), headers, .{});
defer req.deinit();
if (request_cp.body.len > 0) if (request_cp.body.len > 0)
req.transfer_encoding = .{ .content_length = request_cp.body.len }; req.transfer_encoding = .{ .content_length = request_cp.body.len };
try req.start(); try req.start();
@ -210,11 +211,7 @@ pub const AwsHttp = struct {
content_length = std.fmt.parseInt(usize, h.value, 10) catch 0; content_length = std.fmt.parseInt(usize, h.value, 10) catch 0;
} }
// TODO: This is still stupid. Allocate a freaking array var response_data = try self.allocator.alloc(u8, content_length);
var resp_payload = try std.ArrayList(u8).initCapacity(self.allocator, content_length);
defer resp_payload.deinit();
try resp_payload.resize(content_length);
var response_data = try resp_payload.toOwnedSlice();
errdefer self.allocator.free(response_data); errdefer self.allocator.free(response_data);
_ = try req.readAll(response_data); _ = try req.readAll(response_data);
log.debug("raw response body:\n{s}", .{response_data}); log.debug("raw response body:\n{s}", .{response_data});