[英]C GTK+ segfault if call gtkfilechooser after calling any function
Linux IBM370 3.5.0-17-generic #28-Ubuntu SMP Tue Oct 9 19:31:23 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
gcc version 4.7.2 (Ubuntu/Linaro 4.7.2-2ubuntu1)
ldd (Ubuntu EGLIBC 2.15-0ubuntu20) 2.15
GTK+ 2.24.13-0ubuntu2 and 3.2.4-2 - the same behavior
Gnome bugzilla中有一些報告:
https://mail.gnome.org/archives/gtk-devel-list/2012-June/msg00017.html
問題是gtkfilechooser在第二個調用甚至第一個調用時崩潰了
GLib (gthread-posix.c): Unexpected error from C library during 'pthread_setspecific': Invalid argument. Aborting.
Aborted (core dumped)
我發現運行后台線程時出現了問題。
g_thread_new("vm refresh thread", get_vm_list, (gpointer) session);
這是文件選擇器功能
char *
gtk_select_dir(char *label)
{
GtkWidget *select_dir;
char *dirpath=NULL;
select_dir = gtk_file_chooser_dialog_new(label, GTK_WINDOW(main_window),
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL );
if (gtk_dialog_run(GTK_DIALOG (select_dir) ) == GTK_RESPONSE_ACCEPT)
{
dirpath = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER (select_dir) );
}
gtk_widget_destroy(select_dir);
return (dirpath);
}
沒有線程運行時,一切正常。 在線程運行時,從主線程調用此函數會導致崩潰。 線程完成並退出后,對該函數的任何調用都會導致segfault。 這是gdb的輸出
(gdb) backtrace
#0 0x00007f7d4aff6425 in __GI_raise (sig=<optimized out>) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
#1 0x00007f7d4aff9b8b in __GI_abort () at abort.c:91
#2 0x00007f7d4b9ed95d in g_thread_abort (status=<optimized out>, function=function@entry=0x7f7d4baad358 "pthread_setspecific")
at /build/buildd/glib2.0-2.34.1/./glib/gthread-posix.c:76
#3 0x00007f7d4ba58215 in g_private_set (key=key@entry=0x7f7d4a192ce0 <current_cancellable>, value=0x1c21a80)
at /build/buildd/glib2.0-2.34.1/./glib/gthread-posix.c:1024
#4 0x00007f7d49e75400 in g_cancellable_push_current (cancellable=<optimized out>) at /build/buildd/glib2.0-2.34.1/./gio/gcancellable.c:203
#5 0x00007f7d49e9c224 in io_job_thread (data=0x1fe1ba0, user_data=<optimized out>) at /build/buildd/glib2.0-2.34.1/./gio/gioscheduler.c:158
#6 0x00007f7d4ba3ee62 in g_thread_pool_thread_proxy (data=<optimized out>) at /build/buildd/glib2.0-2.34.1/./glib/gthreadpool.c:309
#7 0x00007f7d4ba3e645 in g_thread_proxy (data=0x1c0b320) at /build/buildd/glib2.0-2.34.1/./glib/gthread.c:797
#8 0x00007f7d4b386e9a in start_thread (arg=0x7f7d3e240700) at pthread_create.c:308
#9 0x00007f7d4b0b3cbd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:112
#10 0x0000000000000000 in ?? ()
這個問題完全阻止了我使用線程...是描述的錯誤還是我做錯了什么?
答案是不正確使用libxml2
基於libxml2文檔( http://xmlsoft.org/threads.html ),我們應該只在“主”線程中調用xmlInitParser(),但是我們要多次調用xmlInitParser()。 使用xmlCleanupParser的正確方法應該是在退出前立即調用並且只能調用一次。 但是我們多次調用xmlCleanupParser。
問題出在忽略它的導入源代碼中
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.