Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ All notable changes to this project will be documented in this file.

- Added the `use_bundled_tls` build option. Applications can keep TLS enabled
while replacing Dusty's pinned tls.zig dependency with a compatible module.
- Server and client connections now call `tls.Connection.deinit` on close
when the TLS module declares one, so an injected module backed by a C
library (one `SSL` object per connection) does not leak per connection.
- `Listener.kernel_backlog` now defaults to the system's limit, `net.core.somaxconn`
on Linux, instead of 1024. A full accept queue makes Linux drop new connections,
which then wait a second or more to retry.
Expand Down
8 changes: 8 additions & 0 deletions src/client.zig
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,14 @@ pub const Connection = struct {
}

pub fn deinit(self: *Connection) void {
if (build_options.use_tls) {
// See server.zig `Connection.deinit`: only a TLS module that owns
// per-connection state declares `deinit`.
if (@hasDecl(tls.Connection, "deinit")) {
if (self.tls_conn) |*c| c.deinit();
}
self.tls_conn = null;
}
self.stream.close(self.io);
if (self.protocol == .https) {
self.allocator.free(self.tls_tcp_read_buffer);
Expand Down
9 changes: 9 additions & 0 deletions src/server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,15 @@ pub const Connection = struct {
}

pub fn deinit(self: *Connection) void {
if (build_options.use_tls) {
// tls.zig's Connection owns no memory and has no deinit; a TLS
// module backed by a C library (one SSL object per connection)
// frees it here.
if (@hasDecl(tls.Connection, "deinit")) {
if (self.tls_conn) |*c| c.deinit();
}
self.tls_conn = null;
}
self.allocator.free(self.buffers);
}

Expand Down
Loading