diff options
author | 2022-11-12 18:32:53 -0800 | |
---|---|---|
committer | 2022-11-12 18:32:53 -0800 | |
commit | 1cce9da80a51d49e423223f24f94fee6a044ab10 (patch) | |
tree | 56daa58619a6544ec6a6a60334e2db051f7a274b /src/http_client_async.zig | |
parent | 21bf3ddaf23c842dc12a1d76dbd3b48daf08f349 (diff) | |
download | bun-1cce9da80a51d49e423223f24f94fee6a044ab10.tar.gz bun-1cce9da80a51d49e423223f24f94fee6a044ab10.tar.zst bun-1cce9da80a51d49e423223f24f94fee6a044ab10.zip |
Fix memory leak in gzip pool + add test for gzip'd data
Diffstat (limited to 'src/http_client_async.zig')
-rw-r--r-- | src/http_client_async.zig | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/src/http_client_async.zig b/src/http_client_async.zig index 495a3889f..06903db3a 100644 --- a/src/http_client_async.zig +++ b/src/http_client_async.zig @@ -652,7 +652,7 @@ pub const InternalState = struct { } if (this.compressed_body) |body| { - ZlibPool.instance.put(body) catch unreachable; + ZlibPool.put(body); this.compressed_body = null; } @@ -666,12 +666,7 @@ pub const InternalState = struct { switch (this.encoding) { Encoding.gzip, Encoding.deflate => { if (this.compressed_body == null) { - if (!ZlibPool.loaded) { - ZlibPool.instance = ZlibPool.init(default_allocator); - ZlibPool.loaded = true; - } - - this.compressed_body = ZlibPool.instance.get() catch unreachable; + this.compressed_body = ZlibPool.get(default_allocator); } return this.compressed_body.?; @@ -695,8 +690,8 @@ pub const InternalState = struct { gzip_timer = std.time.Timer.start() catch @panic("Timer failure"); body_out_str.list.expandToCapacity(); - defer ZlibPool.instance.put(buffer_) catch unreachable; - ZlibPool.decompress(buffer.list.items, body_out_str) catch |err| { + defer ZlibPool.put(buffer_); + ZlibPool.decompress(buffer_.list.items, body_out_str) catch |err| { Output.prettyErrorln("<r><red>Zlib error<r>", .{}); Output.flush(); return err; @@ -1725,7 +1720,7 @@ pub fn handleResponseBody(this: *HTTPClient, incoming_data: []const u8) !bool { buffer.list.ensureTotalCapacityPrecise(buffer.allocator, this.state.body_size) catch {}; } - const remaining_content_length = this.state.body_size - buffer.list.items.len; + const remaining_content_length = this.state.body_size -| buffer.list.items.len; var remainder = incoming_data[0..@minimum(incoming_data.len, remaining_content_length)]; _ = try buffer.write(remainder); |