[ previous ] [ next ] [ threads ]
 To :  yate@v...
 From :  Cristian Andrei Calin <kman@t...>
 Subject :  workaround BSD dlclose() bug
 Date :  Sat, 3 Apr 2004 13:01:32 +0300
I've been doing some digging last night on the segfault we are getting when trying to run yate on freebsd and I came up with this: http://sources.redhat.com/ml/bug-glibc/2000-02/msg00054.html

It is linux related, but it seems to be fixed on linux for now, sadly BSDs have the same problem and older Linux distros are affected as well, but momentarely there is no way to fix it, so we need to workaround this.

In short the problem is this: when using a static C++ object in a shared library, that object registers an exit function which gets called when we call exit() in the main module. By dlclose()-ing that library before we exit that memory aria becomes invalid, but the exit function is still registered, and when we exit yate we ge the segfaut because we are trying to access invalid memory.

So far I came up with two workarounds, but I am not so sure as to how much they affect normal operation (well, at list the segfault goles away :) ).
1) we do not call dlclose() ourselvs and let the system do it for us, could be a memory leak though and I do not sugest doing it, I am not entirely sure, but I think the OS frees all the memory of the program once it exits, including dlopen()-ed libraries.
2) do not make the objects static, this works so far and, from what I tested, doesn't have any side-effect.

The elegant way would be to unregister the exit function manually and call it before dlclose(), but at this point in time I do not know how to do that.