2017-05-29 75 views
0

我們已經移植了一個應用程序,在內核4.10.1的Linux上運行。程序失敗似乎在__GI_abort()調用中掛起,稍後SIGABRT被髮出以防止再次寫入錯誤日誌文件的進程發生。這個相同的程序在Linux內核2.6上運行。堆棧跟蹤和代碼已附加。任何建議都會有幫助。謝謝。C程序在fopen時失敗,附帶堆棧跟蹤

我們早前曾建兩個4.10.1內核和應用程序中使用GCC 6.3.1 的應用已經編有: gcc版本6.3.1 20161221(紅帽6.3.1-1)(GCC)

堆棧跟蹤:

(gdb) where 
#0 __lll_lock_wait_private() at ../sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:95 
#1 0x00007f8f1c16ffb2 in __GI___libc_malloc (bytes=140252631706336, [email protected]=552) at malloc.c:2923 
#2 0x00007f8f1c15905d in __fopen_internal (filename=0x7ffeb54deac0 "/tmp/logs/app_exit.log", mode=0x497fc2 "a+", is32=1) at iofopen.c:69 
#3 0x0000000000477690 in fep_sigbus_handler (signum=6, info=0x7ffeb54decb0, ptr=0x7ffeb54deb80) at app_util.c:559 
#4 <signal handler called> 
#5 __GI_raise ([email protected]=6) at ../sysdeps/unix/sysv/linux/raise.c:58 
#6 0x00007f8f1c12151a in __GI_abort() at abort.c:89 
#7 0x00007f8f1c169d68 in __malloc_assert (
    [email protected]=0x7f8f1c277f90 "(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)", [email protected]=0x7f8f1c274807 "malloc.c", [email protected]=2403, 
    [email protected]=0x7f8f1c2787d8 <__func__.11266> "sysmalloc") at malloc.c:301 
#8 0x00007f8f1c16d5b6 in sysmalloc ([email protected]=560, av=0x7f8f1c4aaae0 <main_arena>) at malloc.c:2400 
#9 0x00007f8f1c16e63a in _int_malloc ([email protected]=0x7f8f1c4aaae0 <main_arena>, [email protected]=552) at malloc.c:3862 
#10 0x00007f8f1c16ff14 in __GI___libc_malloc ([email protected]=552) at malloc.c:2925 
#11 0x00007f8f1c15905d in __fopen_internal (filename=0xf4cda4 <file_tbl+4> "/etc/app_config.dat", mode=0x48b735 "r", is32=1) 
    at iofopen.c:69 
#12 0x000000000042e96c in load_conversion_file (filename=0xf4cda4 <file_tbl+4> "/etc/app_config.dat") at app_config.c:1817 
#13 0x000000000042ebc2 in load_all_conversion_files() at app_config.c:1864 
#14 0x000000000042eeb9 in app_config_init() at app_config.c:1958 
#15 0x0000000000403d9e in main (argc=1, argv=0x7ffeb54df6e8) at app_main.c:271 

static int load_conversion_file(const char* filename) 
{ 
    int  rc = FAILURE; 
    FILE* fd = NULL; 
    int  parsedbg = (app_debug_mask & APP_DBG_PARSECONV) ? 1 : 0; 
    AppCfg* pcfg; 

    pcfg = (AppCfg*) malloc(sizeof(AppCfg)); 

    if (pcfg == NULL) 
     LOG(APP_DBG_ERROR, BLANK_TID, ("error allocating AppCfg\n")); 

    else if ((fd = fopen(filename, "r")) == NULL) 
     LOG(APP_DBG_CONFIG, BLANK_TID, ("error opening conversion file: %s\n", 
               filename)); 

    else if (app_parse_file(fd, pcfg, parsedbg) != 0) 
     LOG(APP_DBG_CONFIG, BLANK_TID, ("Parser error %s on line %d at token <%s>\n", 
               app_parser_get_error_string(), 
               app_parser_get_error_line(), 
               app_parser_get_error_token())); 
. 
. 
. 
} 
+2

在我看來,像你在代碼中的其他地方有一個堆腐敗。嘗試用valgrind運行它來找到它。 – kolrabi

回答

0

有在的功能之一的釋放calloc()分配內存,而這函數則fopen之前被調用()。該函數的代碼填充了緩衝區並且也超過了最後一個條目。修復之後,問題就解決了。然而,在早期版本的linux中,使用舊版本的gcc構建的代碼沒有在malloc()中聲明並中止。

+0

不同的庫版本以不同的方式做事。爲什麼他們會有新版本?較新的分配器可能更適合多線程,更少的內存碎片等。當你做錯事情時,它恰好會失敗。 –