emergence problem! I need your help!

Platfrom Rredhat Linux 7.2, I called the system function gethostbyname, then I used memory leak tools(mtrace and valgrind) to trace memory leak, I found the gethostbyname having a memory leak.

I can use command "man freehostent", but I can not use, the gcc compiler told me the function "freehostent" not found. What can I do?

My example source as follow :

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <mcheck.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
typedef unsigned int u_int32;
char serv[2][256]={{"192.168.1.168"},{"ntp.psh.com.cn"}};

int main(int argc, char *argv[])
{
 mtrace();
 u_int32 num;  //unsigned int32;
 struct hostent *hp;
 if ((hp = gethostbyname(serv[1]) ) != 0) {
  memmove((char *)&num, hp->h_addr, sizeof(u_int32));
  printf("OK\n");
 }
 //freehostent(hp);
 return 1;
}

 

best regards!

Firmstone Zhang

Reply via email to