Giter VIP home page Giter VIP logo

Comments (3)

HardySimpson avatar HardySimpson commented on August 19, 2024

我现在不在机器旁边,估计要下周才能测试这个问题,初步猜测,是不是你用的zlog版本比较旧?原先有版本有这种问题,重复init和fini会有导致内存错误。可以去github上下最新的1.2.10版试试看。
在 2013-7-26 AM9:33,"sh19871122" [email protected]写道:

我将程序中的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
ar_ptr =
p =
hook = 0
#1 #1 0x00007f12fb181d0e in
zc_hashtable_del (a_table=0x129d3c0) at zc_hashtable.c:80
i =
p =
q =
#2 #2 0x00007f12fb17c1c6 in
zlog_mdc_del (a_mdc=0x12c1000) at mdc.c:36
No locals.
#3 #3 0x00007f12fb1812fb in
zlog_thread_del (a_thread=0x129d470) at thread.c:45
No locals.
#4 #4 0x00000036584369f1 in
__run_exit_handlers (status=0) at exit.c:78
atfct =
onfct =
cxafct =
#5 #5 exit (status=0) at
exit.c:100
No locals.
#6 #6 0x000000365841ee64 in
_libc_start_main (main=0x41e8c0 <main(int, char*)>, argc=1,
ubp_av=0x7fff4b937d38, init=,
fini=, rtld_fini=, stack_end=0x7fff4b937d28) at libc-start.c:258
result =
unwind_buf = {cancel_jmp_buf = {{jmp_buf = {0, 401847908166741622,
4219392, 140734461345072, 0, 0, -401610168829006218,
432088316090986102}, mask_was_saved = 0}}, priv = {pad = {0x0, 0x0,
0x451e80, 0x7fff4b937d38}, data = {prev = 0x0,
cleanup = 0x0, canceltype = 4529792}}}
not_first_call =
#7 #7 0x0000000000406229 in
_start ()
No symbol table info available.


Reply to this email directly or view it on GitHubhttps://github.com//issues/36
.

from zlog.

hallelujah-shih avatar hallelujah-shih commented on August 19, 2024

直接上代码,如果代码直接构造,然后析构没问题,如果中间随便调用了一个宏之后再析构程序退出的时候将会出现段错,谢谢你抽时间看了问题,非常感谢

/*

  • =====================================================================================
    *
  •   Filename:  test.cpp
    
  • Description:
  •    Version:  1.0
    
  •    Created:  2013年07月26日 15时29分32秒
    
  •   Revision:  none
    
  •   Compiler:  gcc
    
  •     Author:  Hallelujah (shih), [email protected]
    
  •     编译:g++ test.cpp -g -lzlog -lpthread
    
  •     运行:./a.out 
    
  •     当运行不带参数的时候直接段错,当带一个参数的时候正常:./a.out 1
    
  • Organization:
  • =====================================================================================
    */

#include <zlog.h>

zlog_category_t *my_log;

int main(int argc, char *argv[])
{
if (zlog_init("analysistcp_log.conf"))
{
if (zlog_init(NULL))
return -1;
}

if ((my_log = zlog_get_category("analysistcp_main")) == 0)
{
    zlog_fini();
    zlog_init(NULL);
    my_log = zlog_get_category("analysistcp_main");
}

if (argc != 2)
{
    zlog_error(my_log, "Usage:%s\n", argv[0]);
    zlog_fini();

    return -1;
}

// zlog_info(my_log, "Usage:");
zlog_fini();
return 0;

}

from zlog.

HardySimpson avatar HardySimpson commented on August 19, 2024

问题出在:

static void zlog_clean_rest_thread(void)
{
    zlog_thread_t *a_thread;
    a_thread = pthread_getspecific(zlog_thread_key);
    if (!a_thread) return;
    zlog_thread_del(a_thread);
    return;
}

....

zlog_init() { 
....
    pthread_key_create(&zlog_thread_key, (void (*) (void *)) zlog_thread_del);
    rc = atexit(zlog_clean_rest_thread);
}

在zlog_init的时候,我会调用pthread_key_create来注册删除线程的退出函数,让程序在退出线程的时候删掉zlog的线程私有的内存。但问题是,如果用户程序只有一个主线程,这个函数不其作用,主线程的zlog_thread_t变量不会被清理,所以我增加了一行atexit,让程序在退出主线程的时候清理

你的程序反复调用了zlog_init,所以调用了多次atexit,而这个效果会叠加,导致重复去做释放的事情。。

目前我发布了1.2.11,修正了这个bug。

from zlog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.