I'm having a weird crash on AIX 5.3 deep inside getaddrinfo.

Thinking that it could be a potential multi-threading issue I made
sure that the code is being executed under a mutex. However this
didn't help. AIX docs says that the function should be threadsafe...
but I did this just in case.

The strange part is that the call works most of the time so it's only
under a few specific cases it happen.

gdb shows (when analyzing the core file):

Program terminated with signal 11, Segmentation fault.
#0 0xd03f01d0 in __ns_samename () from /usr/lib/libc.a(shr.o)
(gdb) bt
#0 0xd03f01d0 in __ns_samename () from /usr/lib/libc.a(shr.o)
#1 0xd03d009c in res_nameinquery () from /usr/lib/libc.a(shr.o)
#2 0xd03cff74 in res_queriesmatch () from /usr/lib/libc.a(shr.o)
#3 0xd03cf2b0 in res_nsend () from /usr/lib/libc.a(shr.o)
#4 0xd03f4764 in res_nquery () from /usr/lib/libc.a(shr.o)
#5 0xd03f3f74 in res_nquerydomain () from /usr/lib/libc.a(shr.o)
#6 0xd03f4240 in res_nsearch () from /usr/lib/libc.a(shr.o)
#7 0xd03d83e0 in res_search () from /usr/lib/libc.a(shr.o)
#8 0xd03fa300 in ho_byname2 () from /usr/lib/libc.a(shr.o)
#9 0xd041376c in ho_byname2 () from /usr/lib/libc.a(shr.o)
#10 0xd03cce3c in gethostbyname2 () from /usr/lib/libc.a(shr.o)
#11 0xd03d04b0 in getaddrinfo2 () from /usr/lib/libc.a(shr.o)
#12 0xd03d16f0 in getaddrinfo () from /usr/lib/libc.a(shr.o)

The code in question is quite straight forward and looks like:

bool LookupHost(const char *szHost, int nPort, list
&AddrList, bool bPassive)
bool bRet = false;
char szPort[64] = {0};
struct addrinfo aiHints;
struct addrinfo *paiList = NULL, *p = NULL;

// attempt to overcome multithreaded issues dispite getaddrinfo is
suppose to be threadsafe.
static CMutex Mtx;
CMutexGuard MtxGuard(&Mtx);

sprintf(szPort, "%d", nPort);

memset(&aiHints, 0, sizeof(aiHints));
aiHints.ai_family = AF_UNSPEC;
aiHints.ai_socktype = SOCK_STREAM;

if (bPassive)
aiHints.ai_flags |= AI_PASSIVE;

// Make a dns request
if (getaddrinfo(szHost, szPort, &aiHints, &paiList) != 0)


Can anyone bring any insights?

A side question I have is that I'd like to see and possibly analyze
what threads are alive and what state they're in. This might help on
narrowing this down. Is it also possible to see from the core file
what parameters was sent to getaddrinfo?