C GTK + segfault如果在调用任何函数后调用gtkfilechooser

时间:2013-04-03 15:37:39

标签: c gtk segmentation-fault filechooser

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);
}

没有线程在运行时一切正常。当线程正在运行时,从主线程调用此函数会导致崩溃。线程完成并退出后,对此函数的任何调用都会导致段错误。这是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 ?? ()

这个问题完全阻止我使用线程...是描述的错误还是我做错了什么?

1 个答案:

答案 0 :(得分:0)

答案是正确使用libxml2

  

基于libxml2文档(http://xmlsoft.org/threads.html),我们   应该只在“主”线程中调用xmlInitParser(),但我们是   多次调用xmlInitParser()。正确的使用方法   xmlCleanupParser应该在退出之前立即调用   一旦。但是我们多次调用xmlCleanupParser。

问题在于导入的源代码忽略了它