Memory leakage happened. What's wrong with the code?
static sigjmp_buf jmpbuf=NULL;
static void alarm_func()
{
siglongjmp(jmpbuf, 1);
}
static struct hostent *timeGethostbyname(const char *domain, int timeout)
{
struct hostent *ipHostent = NULL;
jmpbuf=malloc(sizeof(sigjmp_buf));
signal(SIGALRM, alarm_func);
if(sigsetjmp(jmpbuf, 1) != 0)
{
alarm(0);
signal(SIGALRM, SIG_IGN);
return NULL;
}
alarm(timeout);//setting alarm
ipHostent = gethostbyname(domain);
signal(SIGALRM, SIG_IGN);
return ipHostent;
}
something wrong in function timeGethostbyname
.
if I call the function timeGethostbyname
many times.Memory leakage will be happened.
EX:
int main(int argc, char **argv ){
char *servers="www.aaa.bbb.tt";
struct hostent *h;
while(1){
h=timeGethostbyname(servers, 2);
}
return(0);
}