From mboxrd@z Thu Jan 1 00:00:00 1970 From: aaa@bbb.ccc.ddd (Andrew Wallace) To: help-gcc@gnu.org Subject: gcc-gethostbyaddr memory leak Date: Fri, 31 Dec 1999 22:24:00 -0000 Message-ID: <82peet$l1r$1@perki.connect.com.au> X-SW-Source: 1999-12n/msg00137.html Message-ID: <19991231222400.kY0SDv4E945U_Cts0HlYzcF4IVensA65uSEOi98FF_g@z> I hope this is the correct list, this looks like a gcc problem. I don't think it's a programming question. The following code leaks when it is passed an address that it cannot find. If anybody has any suggestions I would appreciate any help. Thanks, Andrew System info: gcc version 2.95.1 19990816 Linux Redhat v6.0, I'm sorry I can't find the kernel version // simple program to demo the leak in gethostbyaddr when a // name is not found #include #include #include #include #include char* GetAddrName(char* clean_address) { static int init_state; struct in_addr ip; if (inet_aton(clean_address, &ip)) { struct hostent* hostinfo = gethostbyaddr((char*)&ip, sizeof(ip), AF_INET); if (hostinfo) return hostinfo->h_name; if (h_errno != 1) // display anything but HOST NOT FOUND printf("ERROR: gethostbyaddr (%s,%d)(%s,%d)(%s)\n", hstrerror(h_errno), h_errno, strerror(errno), errno, clean_address); } // if else printf("ERROR: address seems invalid: %s\n", clean_address); return NULL; } int main(int argc, char** argv) { int x; char buff[124]; for (x = 0; x < 50000; x++) { sprintf(buff,"%d.%d.%d.%d",210,10,3, (random()%254) + 1); printf("%-20.20s %s\n", GetAddrName(buff), buff); if (!(x % 100)) sleep(1); } }