-
Notifications
You must be signed in to change notification settings - Fork 721
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
程序析构时出现段错的问题 #36
Comments
我现在不在机器旁边,估计要下周才能测试这个问题,初步猜测,是不是你用的zlog版本比较旧?原先有版本有这种问题,重复init和fini会有导致内存错误。可以去github上下最新的1.2.10版试试看。
|
直接上代码,如果代码直接构造,然后析构没问题,如果中间随便调用了一个宏之后再析构程序退出的时候将会出现段错,谢谢你抽时间看了问题,非常感谢 /*
#include <zlog.h> zlog_category_t *my_log; int main(int argc, char *argv[])
} |
问题出在:
....
在zlog_init的时候,我会调用pthread_key_create来注册删除线程的退出函数,让程序在退出线程的时候删掉zlog的线程私有的内存。但问题是,如果用户程序只有一个主线程,这个函数不其作用,主线程的zlog_thread_t变量不会被清理,所以我增加了一行atexit,让程序在退出主线程的时候清理 你的程序反复调用了zlog_init,所以调用了多次atexit,而这个效果会叠加,导致重复去做释放的事情。。 目前我发布了1.2.11,修正了这个bug。 |
我将程序中的zlog更换为其他日志系统时,没问题,或是程序中不使用log时也没问题,使用zlog的时候每次主程序退出时将段错。我将zlog单独写个简单程序也没问题,我的链接库有pthread gtest zlog rt pcap,执行代码如下:
29 zlog_category_t *my_log;
30
31 int main(int argc, char *argv[])
32 {
33 if (zlog_init("analysistcp_log.conf"))
34 {
35 if (zlog_init(NULL))
36 return -1;
37 }
38
39 if ((my_log = zlog_get_category("analysistcp_main")) == NULL)
40 {
41 zlog_fini();
42 zlog_init(NULL);
43 my_log = zlog_get_category("analysistcp_main");
44 }
45
46 if (argc != 2)
47 {
48 zlog_error(my_log, "Usage: %s \n", argv[0]);
49 zlog_fini();
50 return 0;
51 }
详细的栈信息如下:
Program terminated with signal 11, Segmentation fault.
#0 __libc_free (mem=0x20) at malloc.c:3709
3709 if (chunk_is_mmapped(p)) /* release mmapped memory. */
(gdb) bt full
#0 __libc_free (mem=0x20) at malloc.c:3709
#1 0x00007f12fb181d0e in zc_hashtable_del (a_table=0x129d3c0) at zc_hashtable.c:80
#2 0x00007f12fb17c1c6 in zlog_mdc_del (a_mdc=0x12c1000) at mdc.c:36
No locals.
#3 0x00007f12fb1812fb in zlog_thread_del (a_thread=0x129d470) at thread.c:45
No locals.
#4 0x00000036584369f1 in __run_exit_handlers (status=0) at exit.c:78
#5 exit (status=0) at exit.c:100
No locals.
#6 0x000000365841ee64 in __libc_start_main (main=0x41e8c0 <main(int, char**)>, argc=1, ubp_av=0x7fff4b937d38, init=,
#7 0x0000000000406229 in _start ()
No symbol table info available.
The text was updated successfully, but these errors were encountered: