summaryrefslogtreecommitdiffstats
path: root/contrib/restricted/emscripten/system/lib/libc/musl/src/network/freeaddrinfo.c
blob: c4016d9f7c246dd67742d7d3177a064e448fb4ed (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdlib.h>
#include <stddef.h>
#include <netdb.h>
#include "lookup.h"
#include "lock.h"

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
}