apple / swift-async-dns-resolver

A Swift library for asynchronous DNS requests, wrapping c-ares with Swift-friendly APIs and data structures.
Apache License 2.0
82 stars 12 forks source link

Avoid memory leak from hostent #30

Closed dieb closed 4 months ago

dieb commented 4 months ago

More context on issue #29

Motivation

Observed memory leak in Leaks instrument caused by A and AAAA queries.

Modifications

hostent is internally allocated by ares_parse_a_reply when we pass non-null pointer, and it expects the caller to freehostent(hostent).

Here we pass host=null to avoid the code branch that allocates hostent here. It looks like this is fine since we don't need hostent.

Result

No hostent is allocated, leak count significantly reduced.

For reference, reduced from 2k leaks to 600 leaks, when resolving about ~200 domains (A and AAAA records)

Test Plan

[Describe the steps you took, or will take, to qualify the change - such as adjusting tests and manual testing.]

yim-lee commented 4 months ago

Need to fix webhook and run CI before merging.

yim-lee commented 4 months ago

@swift-server-bot test this please