SEGV when dlopen()ing Gnome code

   I am developing an application which loads its UI through dlopen()
so that the main application doesn't directly depend on the Gnome
libraries. However, when I load the Gnome UI, I get a segfault on exit
if dlclose() was called before exit.

   Here is some sample code which illustrates the problem:

-----8<----- gnome.c -----8<-----
#include <gnome.h>

static gint timeout(gpointer p_data) { gtk_main_quit(); return(FALSE); }

int main (void) {
    char *p_args[] = { };
    gnome_init("gnome", "42", 1, p_args);
    gtk_timeout_add(1, timeout, NULL);
-----8<----- gnome.c -----8<-----

   This program, when compiled with the following command line, works
flawlessly :

$ gcc `gnome-config --cflags gnomeui` -o gnome gnome.c \
      `gnome-config --libs gnomeui
$ ./gnome

   However, if I use the following program to dlopen() the first one:

-----8<----- dlgnome.c -----8<-----
#include <dlfcn.h>

int main(void) {
    void * lib; int (*gnome_main) (void);
    lib = dlopen("./", RTLD_LAZY);
    gnome_main = dlsym(lib, "main");
-----8<----- dlgnome.c -----8<-----

   When compiling with the following compilation options:

$ gcc `gnome-config --cflags gnomeui` -fPIC -shared -o gnome.c \
      `gnome-config --libs gnomeui | sed 's,-rdynamic,,'`
$ gcc dlgnome.c -o dlgnome -ldl
$ ./dlgnome
zsh: 8266 segmentation fault (core dumped)  ./dlgnome

   It segfaults and I could not find out the reason for this. I can
imagine it may be due to some signal handlers, but fiddling around with
sigaction() and gnome_client_disable_master_connection() didn't show
much. And gdb's backtrace is stuck in libc.

   I notice that omitting the last dlclose(lib); line makes the
application exit cleanly, so it really looks like some registered
callbacks are not cleaned when returning from gtk_main(), but I have no
idea what they may be.

   Has anyone ever went through such a problem ? Or does anyone know
of an application that successfully dlopen()s a Gnome library and then
flawlessly dlclose()s it ?

   Or am I maybe missing something obvious ?

Many thanks for any pointers or documentation about this,
Samuel Hocevar <sam zoy org> <>
for DVDs in Linux screw the MPAA and ; do dig $ ; done | \
      perl -ne 's/\.//g; print pack("H224",$1) if(/^x([^z]*)/)' | gunzip

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]