status-im / nim-chronos

Chronos - An efficient library for asynchronous programming
https://status-im.github.io/nim-chronos/docs/chronos
Apache License 2.0
353 stars 51 forks source link

fixing unfreed memory leak with `freeAddrInfo()` #425

Closed rockcavera closed 1 year ago

rockcavera commented 1 year ago

Apparently all documentation for getaddrinfo() advises to call freeaddrinfo() to free resources that were dynamically allocated.

I was able to verify the leak on Windows as I haven't tested it on other systems.

On Windows, creating a local DNS server that returns A and AAAA queries for 127.0.0.1 and ::1, respectively, I found that resolveTAddress() leaks approximately 2MB, 4MB, and 6MB, for 10,000, 20,000, and 30,000 queries, respectively. Something that doesn't happen by calling freeAddrInfo().

Therefore, a program that runs without interruption will be leaking memory after each resolveTAddress() call.