@@ -1695,6 +1695,7 @@ fn setConnection(ctx: *Ctx, res: anyerror!void) !void {
1695
1695
.port = ctx .data .conn .port ,
1696
1696
},
1697
1697
};
1698
+
1698
1699
// remove old pointer, now useless
1699
1700
const old_conn = ctx .data .conn ;
1700
1701
defer ctx .req .client .allocator .destroy (old_conn );
@@ -1777,6 +1778,11 @@ pub fn async_connectTcp(
1777
1778
.port = port ,
1778
1779
.protocol = protocol ,
1779
1780
})) | conn | {
1781
+ // remove old ctx pointer, now useless
1782
+ const old_conn = ctx .data .conn ;
1783
+ defer ctx .req .client .allocator .destroy (old_conn );
1784
+ defer ctx .req .client .allocator .free (old_conn .host );
1785
+
1780
1786
ctx .data .conn = conn ;
1781
1787
ctx .req .connection = conn ;
1782
1788
return ctx .pop ({});
@@ -2256,7 +2262,13 @@ pub fn async_open(
2256
2262
2257
2263
// add fields to connection
2258
2264
ctx .data .conn .protocol = protocol ;
2265
+
2266
+ // free the previous host
2267
+ client .allocator .free (ctx .data .conn .host );
2268
+
2259
2269
ctx .data .conn .host = try client .allocator .dupe (u8 , host .raw );
2270
+ errdefer client .allocator .free (ctx .data .conn .host );
2271
+
2260
2272
ctx .data .conn .port = port ;
2261
2273
2262
2274
return client .async_connect (host .raw , port , protocol , ctx , setRequestConnection );
@@ -2419,14 +2431,22 @@ pub const Ctx = struct {
2419
2431
_tls_write_buf : [cipher .max_ciphertext_record_len ]u8 = undefined ,
2420
2432
2421
2433
pub fn init (io : * IO , req : * Request ) ! Ctx {
2422
- const connection = try req .client .allocator .create (Connection );
2434
+ const allocator = req .client .allocator ;
2435
+
2436
+ const connection = try allocator .create (Connection );
2437
+ errdefer allocator .destroy (connection );
2438
+
2439
+ const host = try allocator .dupe (u8 , "" );
2440
+ errdefer allocator .free (host );
2441
+
2423
2442
connection .* = .{
2424
2443
.stream = undefined ,
2425
2444
.tls_client = undefined ,
2426
2445
.protocol = undefined ,
2427
- .host = undefined ,
2446
+ .host = host ,
2428
2447
.port = undefined ,
2429
2448
};
2449
+
2430
2450
return .{
2431
2451
.req = req ,
2432
2452
.io = io ,
0 commit comments