Skip to content
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

Don't free memory not allocated by getaddrinfo(3) with freeaddrinfo #320

Merged
merged 1 commit into from
Feb 18, 2025

Conversation

nmeum
Copy link
Contributor

@nmeum nmeum commented Feb 13, 2025

ai_unique_ptr frees objects via a custom deleter using freeaddrinfo(3). However, in ai_make_hint the ai_unique_ptr is used for a addrinfo structure allocated via new. This is undefined behavior as freeaddrinfo(3) is only defined for structures returned by getaddrinfo(3).

This commit fixes this by using a standard std::unique_ptr here with the default delete function which frees the memory using delete.

Just like #319 this has been discovered due to test failures on certain Alpine Linux Edge architectures.

ai_unique_ptr frees objects via a custom deleter using freeaddrinfo(3).
However, in ai_make_hint the ai_unique_ptr is used for a addrinfo
structure allocated via new. This is undefined behavior as freeaddrinfo
is only defined for structures returned by getaddrinfo().

This commit fixes this by using a standard std::unique_ptr here with
the default delete function which frees the memory using delete.
@nmeum nmeum mentioned this pull request Feb 13, 2025
@neheb
Copy link
Contributor

neheb commented Feb 13, 2025

use std::make_unique

@rakshasa rakshasa merged commit fe624b9 into rakshasa:master Feb 18, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants