Hello,
I am debugging a C++ application that was ported from PostgreSQL to
DB2 UDB (v8.1.0.112) on Linux and have run across a problem. We have
a singleton object that handles connection pooling, creating
connections, etc. This object is declared static to ensure
destructors run before the program exits. The problem occurs when our
destructors run as the program is exiting. They attempt to free up DB2
resources that DB2 apparently has already freed and we receive a
segmentation fault.
If I remove 'static' from the singleton object, all *seems* to be
well. Can I depend on DB2 always freeing up all handles, connections,
etc before a program exits? If not, is there a way I can prevent
their cleanup code from running, or delay it until after our static
destructors have executed? Is the DB2 cleanup code run through it's
own static destructor, a signal handler or some other mechanism?
Thanks in advance for any help!
Donna Lenharth
Knut Stolze - 06 Feb 2007 12:19 GMT
> Hello,
>
[quoted text clipped - 13 lines]
> destructors have executed? Is the DB2 cleanup code run through it's
> own static destructor, a signal handler or some other mechanism?
I don't know for sure, but I'd think that DB2 installs an exit handler.
Have you verified in a debugger where exactly the segfault occurs? I would
think that even if DB2 freed up some resources before, you should not see a
segfault.

Signature
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
donna.lenharth@gmail.com - 06 Feb 2007 15:25 GMT
The seg fault occurs inside libdb2.so on the call the SQLDisconnect.
If I comment out the call to SQLDisconnect, a seg fault occurs on the
call to SQLFreeHandle.
Is there a way I can determine if the resource has already been freed
before attempting to free it again?
> I don't know for sure, but I'd think that DB2 installs an exit handler.
>
[quoted text clipped - 8 lines]
>
> - Show quoted text -
Knut Stolze - 06 Feb 2007 15:27 GMT
> The seg fault occurs inside libdb2.so on the call the SQLDisconnect.
> If I comment out the call to SQLDisconnect, a seg fault occurs on the
> call to SQLFreeHandle.
>
> Is there a way I can determine if the resource has already been freed
> before attempting to free it again?
You could try to collect a CLI trace. That should contain the information
about disconnects.

Signature
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany