diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bun.js/api/bun/dns_resolver.zig | 22 | ||||
-rw-r--r-- | src/deps/c_ares.zig | 8 |
2 files changed, 16 insertions, 14 deletions
diff --git a/src/bun.js/api/bun/dns_resolver.zig b/src/bun.js/api/bun/dns_resolver.zig index 7364c2ffa..8232318a2 100644 --- a/src/bun.js/api/bun/dns_resolver.zig +++ b/src/bun.js/api/bun/dns_resolver.zig @@ -1497,8 +1497,10 @@ pub const DNSResolver = struct { var pending: ?*CAresReverse = key.lookup.head.next; var prev_global = key.lookup.head.globalThis; + // The callback need not and should not attempt to free the memory + // pointed to by hostent; the ares library will free it when the + // callback returns. var array = addr.toJSReponse(this.vm.allocator, prev_global, ""); - defer addr.deinit(); array.ensureStillAlive(); key.lookup.head.onComplete(array); bun.default_allocator.destroy(key.lookup); @@ -2320,7 +2322,7 @@ pub const DNSResolver = struct { }, }; - var servers: [*c]c_ares.struct_ares_addr_port_node = undefined; + var servers: ?*c_ares.struct_ares_addr_port_node = null; const r = c_ares.ares_get_servers_ports(channel, &servers); if (r != c_ares.ARES_SUCCESS) { const err = c_ares.Error.get(r).?; @@ -2333,21 +2335,21 @@ pub const DNSResolver = struct { var i: u32 = 0; var cur = servers; - while (cur != null) : ({ + while (cur) |current| : ({ i += 1; - cur = cur.*.next; + cur = current.next; }) { // Formatting reference: https://nodejs.org/api/dns.html#dnsgetservers // Brackets '[' and ']' consume 2 bytes, used for IPv6 format (e.g., '[2001:4860:4860::8888]:1053'). // Port range is 6 bytes (e.g., ':65535'). // Null terminator '\0' uses 1 byte. var buf: [INET6_ADDRSTRLEN + 2 + 6 + 1]u8 = undefined; - const family = cur.*.family; + const family = current.family; const ip = if (family == std.os.AF.INET6) blk: { - break :blk c_ares.ares_inet_ntop(family, &cur.*.addr.addr6, buf[1..], @sizeOf(@TypeOf(buf)) - 1); + break :blk c_ares.ares_inet_ntop(family, ¤t.addr.addr6, buf[1..], @sizeOf(@TypeOf(buf)) - 1); } else blk: { - break :blk c_ares.ares_inet_ntop(family, &cur.*.addr.addr4, buf[1..], @sizeOf(@TypeOf(buf)) - 1); + break :blk c_ares.ares_inet_ntop(family, ¤t.addr.addr4, buf[1..], @sizeOf(@TypeOf(buf)) - 1); }; if (ip == null) { globalThis.throwValue(globalThis.createErrorInstance( @@ -2357,15 +2359,15 @@ pub const DNSResolver = struct { return .zero; } - var port = cur.*.tcp_port; + var port = current.tcp_port; if (port == 0) { - port = cur.*.udp_port; + port = current.udp_port; } if (port == 0) { port = IANA_DNS_PORT; } - const size = bun.len(bun.cast([*:0]u8, &buf)); + const size = bun.len(bun.cast([*:0]u8, buf[1..])) + 1; if (port == IANA_DNS_PORT) { values.putIndex(globalThis, i, JSC.ZigString.init(buf[1..size]).withEncoding().toValueGC(globalThis)); } else { diff --git a/src/deps/c_ares.zig b/src/deps/c_ares.zig index b80342996..5098f4e19 100644 --- a/src/deps/c_ares.zig +++ b/src/deps/c_ares.zig @@ -1167,7 +1167,7 @@ const union_unnamed_3 = extern union { addr6: struct_ares_in6_addr, }; pub const struct_ares_addr_node = extern struct { - next: [*c]struct_ares_addr_node, + next: ?*struct_ares_addr_node, family: c_int, addr: union_unnamed_3, }; @@ -1176,7 +1176,7 @@ const union_unnamed_4 = extern union { addr6: struct_ares_in6_addr, }; pub const struct_ares_addr_port_node = extern struct { - next: [*c]struct_ares_addr_port_node, + next: ?*struct_ares_addr_port_node, family: c_int, addr: union_unnamed_4, udp_port: c_int, @@ -1186,8 +1186,8 @@ pub extern fn ares_set_servers(channel: *Channel, servers: [*c]struct_ares_addr_ pub extern fn ares_set_servers_ports(channel: *Channel, servers: [*c]struct_ares_addr_port_node) c_int; pub extern fn ares_set_servers_csv(channel: *Channel, servers: [*c]const u8) c_int; pub extern fn ares_set_servers_ports_csv(channel: *Channel, servers: [*c]const u8) c_int; -pub extern fn ares_get_servers(channel: *Channel, servers: [*c][*c]struct_ares_addr_node) c_int; -pub extern fn ares_get_servers_ports(channel: *Channel, servers: [*c][*c]struct_ares_addr_port_node) c_int; +pub extern fn ares_get_servers(channel: *Channel, servers: *?*struct_ares_addr_port_node) c_int; +pub extern fn ares_get_servers_ports(channel: *Channel, servers: *?*struct_ares_addr_port_node) c_int; pub extern fn ares_inet_ntop(af: c_int, src: ?*const anyopaque, dst: [*c]u8, size: ares_socklen_t) [*c]const u8; pub extern fn ares_inet_pton(af: c_int, src: [*c]const u8, dst: ?*anyopaque) c_int; pub const ARES_SUCCESS = 0; |