Skip to content

Commit ce2eed2

Browse files
committed
Fix memory leaks
1 parent 505fa91 commit ce2eed2

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

src/http/client.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ pub const Request = struct {
306306
fn destroyConnection(self: *Request, connection: *Connection) void {
307307
const client = self._client;
308308
connection.deinit(client.allocator);
309-
errdefer client.connection_pool.destroy(connection);
309+
client.connection_pool.destroy(connection);
310310
}
311311

312312
const AddHeaderOpts = struct {
@@ -2153,6 +2153,7 @@ const IdleConnections = struct {
21532153

21542154
fn get(self: *IdleConnections, secure: bool, host: []const u8, port: u16, blocking: bool) ?*Connection {
21552155
self.mutex.lock();
2156+
defer self.mutex.unlock();
21562157

21572158
var node = self.idle.first;
21582159
while (node) |n| {
@@ -2161,12 +2162,10 @@ const IdleConnections = struct {
21612162
self.count -= 1;
21622163
self.idle.remove(n);
21632164
self.node_pool.destroy(n);
2164-
self.mutex.unlock();
21652165
return connection;
21662166
}
21672167
node = n.next;
21682168
}
2169-
self.mutex.unlock();
21702169
return null;
21712170
}
21722171

@@ -2178,6 +2177,7 @@ const IdleConnections = struct {
21782177
if (self.count == self.max) {
21792178
const oldest = self.idle.popFirst() orelse {
21802179
std.debug.assert(self.max == 0);
2180+
connection.deinit(self.allocator);
21812181
return;
21822182
};
21832183
oldest.data.deinit(self.allocator);

src/main.zig

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,6 @@ fn serveHTTPS(address: std.net.Address) !void {
534534
var listener = try address.listen(.{ .reuse_address = true });
535535
defer listener.deinit();
536536

537-
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
538-
defer arena.deinit();
539-
540537
test_wg.finish();
541538

542539
var seed: u64 = undefined;
@@ -546,9 +543,6 @@ fn serveHTTPS(address: std.net.Address) !void {
546543

547544
var read_buffer: [1024]u8 = undefined;
548545
while (true) {
549-
// defer _ = arena.reset(.{ .retain_with_limit = 1024 });
550-
// const aa = arena.allocator();
551-
552546
const stream = blk: {
553547
const conn = try listener.accept();
554548
break :blk conn.stream;

0 commit comments

Comments
 (0)