getopt: fix null pointer arithmetic ub
[musl] / src / network / freeaddrinfo.c
1 #include <stdlib.h>
2 #include <stddef.h>
3 #include <netdb.h>
4 #include "lookup.h"
5 #include "lock.h"
6
7 void freeaddrinfo(struct addrinfo *p)
8 {
9         size_t cnt;
10         for (cnt=1; p->ai_next; cnt++, p=p->ai_next);
11         struct aibuf *b = (void *)((char *)p - offsetof(struct aibuf, ai));
12         b -= b->slot;
13         LOCK(b->lock);
14         if (!(b->ref -= cnt)) free(b);
15         else UNLOCK(b->lock);
16 }