Skip to content

Fix freeaddrinfo(), which did not match allocation in JS. #16085

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

Merged
merged 1 commit into from
Jan 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions system/lib/libc/musl/src/network/freeaddrinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@

void freeaddrinfo(struct addrinfo *p)
{
#if __EMSCRIPTEN__
// Emscripten's usage of this structure is very simple: we always allocate
// ai_addr, and do not use the linked list aspect at all. There is also no
// aliasing with aibuf.
free(p->ai_addr);
free(p);
#else
size_t cnt;
for (cnt=1; p->ai_next; cnt++, p=p->ai_next);
struct aibuf *b = (void *)((char *)p - offsetof(struct aibuf, ai));
b -= b->slot;
LOCK(b->lock);
if (!(b->ref -= cnt)) free(b);
else UNLOCK(b->lock);
#endif
}