-
Notifications
You must be signed in to change notification settings - Fork 612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ares_gethostbyname Appears to Leak from an 'ares_strdup' at the Conclusion of a Successful Query #439
Comments
ares_getnameinfo() is reverse not forward. Are you sure you're looking at the right path? ares_getaddrinfo() is the forward query (or ares_gethostbyname(), which these days internally calls ares_getaddrinfo()). Our test suite does run through Leak Sanitizer, and it's not showing anything: Can you provide the leak sanitizer output with debug symbols and the full trace? |
Also, I'm assuming you mean 1.18.1 not 1.8.1 (as 1.8.1 never existed). And hquery->name is free'd immediately before hquery in the 2 places where hquery itself is freed. So I really don't see any way that only hquery->name could be left hanging around, but you didn't provide the full leak output so maybe there is more relevant information in that. |
I'm only seeing references to ares_gethostbyname() and not ares_getaddrinfo() in the code, but it looks like you convert the ares_gethostbyname() result into an addrinfo result. You might consider using ares_getaddrinfo(), it was added in the last couple of years. |
Using Visual Leak Detector on Windows/MSVC, I see 7 leaks in |
Yeah, those look to be leaks inside of the test framework gmock itself as far as I can tell. I guess specific to windows since we don't see them on Linux. |
The comment in
is for some other leaks AFAICS. I used Release mode with VLD. |
Confirmed; however, I was trying to ensure package compatibility with Ubuntu 20.04 which offers c-ares-1.15.0 which lacks |
The attached test program also demonstrates the issue and zeros in with
|
It looks like your test case needs MacOS. But on my MacOS instance, leak sanitizer doesn't work with the XCode compiler, and valgrind says it requires linux when trying to install via homebrew. I don't suppose you have a test case that will work on Linux do you? |
Actually, installing llvm via homebrew and using that compiler does allow -fsanitize=leak ... but I'm getting no output indicating a leak when running your test. I found this https://github.com/LouisBrunner/valgrind-macos so I'll try to use that valgrind package once its done compiling. |
Nope, looks like that valgrind doesn't work on MacOS 11.6 which is what I have access to right now, valgrind itself throws an internal assert. Can you compile c-ares with debug symbols so hopefully valgrind will give a line number within c-ares for the leak? The leak you seem to be reporting is actually from reading /etc/hosts when looking up 'localhost'. Do you also get a leak with the same utility if you try looking up a remote host? If not, can you provide your /etc/hosts file? It may be something specific inside of that causing the leak. |
All of the above was generated on Ubuntu 20.04:
The clang/LLVM and valgrind package are:
|
There are no leaks with an external, DNS-resolved host:
The contents of /etc/hosts are:
|
As requested, here is a
|
On your test case, I see these 2 includes that only exist on MacOS for me ...
What do I need to get them on Linux? |
You can just delete the |
Actually, I think I know what is going on here based on your |
The
So I'm assuming most hosts out there are similar where |
@bradh352, looks great! Confirmed on the closure. Thanks for the fast turn and the collaboration on debugging this to root cause. |
When an /etc/hosts lookup is performed, but fails with ENOTFOUND, and a valid RFC6761 Section 6.3 fallback is performed, it could overwrite variables that were already set and therefore leave the pointers dangling, never to be cleaned up. Clean up explicitly on ENOTFOUND when returning from the file parser. Fixes: c-ares#439 Fix By: Brad House (@bradh352)
When invoking
ares_gethostbyname
for a forward DNS name-to-address lookup, there seems to be a leak fromares_strdup
, as reported by the clang/LLVM address sanitizer:This was/is demonstrated against c-ares-1.18.1 using https://github.com/gerickson/opencfnetwork/blob/user/gerickson/github-issue-8-forward-dns-deadlock/third_party/CFNetwork/repo/Host/CFHost.c#L2770 along with the example application https://github.com/gerickson/opencfnetwork/blob/user/gerickson/github-issue-8-forward-dns-deadlock/examples/CFHost/CFHostExample.c.
The text was updated successfully, but these errors were encountered: