RE: [reSIProcate] Memory Leaks
Hi,
I was looking at a fragment of the source code of DnsUtil which you find below.
The getLocalHostName is looking 2x for the hostname, 1x by calling gethostname
and 1x by calling gethostbyname. In the past, it was only gethostname. To me,
it seems that someone wanted to replace the call to gethostname by
gethostbyname but forgot remove the first call. Can someone have a look at it ?
Frederik
DnsUtil::getLocalHostName()
{
char buffer[MAXHOSTNAMELEN];
buffer[0] = '\0';
if (int e = gethostname(buffer,sizeof(buffer)) == -1)
{
if ( e != 0 )
{
int err = getErrno();
switch (err)
{
// !RjS! This makes no sense for non-windows. The
// current hack (see the #define in .hxx) needs
// to be reworked.
case WSANOTINITIALISED:
CritLog( << "could not find local hostname because network not
initialized:" << strerror(err) );
break;
default:
CritLog( << "could not find local hostname:" << strerror(err) );
break;
}
throw Exception("could not find local hostname",__FILE__,__LINE__);
}
}
struct hostent* he;
if ((he = gethostbyname(buffer)) != 0)
{
if (strchr(he->h_name, '.') != 0)
{
strncpy(buffer, he->h_name, sizeof(buffer));
}
else
{
WarningLog( << "local hostname does not contain a domain part");
}
}
return Data(buffer);
}