这段代码第一次进入循环时运行完美,第二次出现get seg错误,如果我再次运行program..quit..run,它也可以完美运行
if ((server=gethostbyname(HOSTA))==NULL){
fprintf(stderr,"\n\tRESOLVE SERVER FAIL\n\n");
exit(3);
}
gdb 中的 bt 给出
Program received signal SIGABRT, Aborted.
0x0012d422 in __kernel_vsyscall ()
(gdb) bt
#0 0x0012d422 in __kernel_vsyscall ()
#1 0x00197681 in raise () from /lib/tls/i686/cmov/libc.so.6
#2 0x0019aab2 in abort () from /lib/tls/i686/cmov/libc.so.6
#3 0x001d124d in ?? () from /lib/tls/i686/cmov/libc.so.6
#4 0x001db341 in ?? () from /lib/tls/i686/cmov/libc.so.6
#5 0x001dcb98 in ?? () from /lib/tls/i686/cmov/libc.so.6
#6 0x001dfc7d in free () from /lib/tls/i686/cmov/libc.so.6
#7 0x001cb85a in fclose () from /lib/tls/i686/cmov/libc.so.6
#8 0x002d0734 in ?? () from /lib/tls/i686/cmov/libnss_files.so.2
#9 0x002d1b9f in _nss_files_gethostbyname_r () from /lib/tls/i686/cmov/libnss_files.so.2
#10 0x002577de in gethostbyname_r () from /lib/tls/i686/cmov/libc.so.6
#11 0x00257036 in gethostbyname () from /lib/tls/i686/cmov/libc.so.6
#12 0x0804a00c in update () at main.h:144
#13 0x0804b247 in main (argc=1, argv=0xbffff4a4) at main.c:78
(gdb) q
注意:我是调试器的菜鸟
我的解释是,我没有释放struct hostent 或 gethostbyname 本身的返回
代码:@pastebin
我究竟做错了什么 ?
编辑:函数update()
进入循环