问一下这里为什么老是Segmentation fault
Program received signal SIGSEGV, Segmentation fault.
Program received signal SIGSEGV, Segmentation fault.
0x00000034a6847e2c in vfprintf () from /lib64/libc.so.6
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.149.el6_6.5.x86_64
(gdb) where
#0 0x00000034a6847e2c in vfprintf () from /lib64/libc.so.6
#1 0x00000034a684f18a in printf () from /lib64/libc.so.6
#2 0x0000000000401de3 in MyPrintf ….
其中,debug_stream不是nil,是在别的地方打开的。
static void MyPrintf(const char* fmt, …)
{
pthread_mutex_lock(&mutex);
printf(“enter \n”);
va_list args;
va_list aq;
va_start(args, fmt);
va_copy(aq,args);
printf(fmt,*args);
fprintf(debug_stream,fmt, *aq);
fflush(debug_stream);
va_end(args);
va_end(aq);
printf(“departure \n”);
pthread_mutex_unlock(&mutex);
}
解决方案:20分
printf(fmt,*args); fprintf(debug_stream,fmt, *aq);
应为
vprintf(fmt,args); vfprintf(debug_stream,fmt, aq);