[asio] Boost-1.65.0 TlsSlot leak on win32

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[asio] Boost-1.65.0 TlsSlot leak on win32

Boost - Users mailing list

Hi,

 

I am using boost version 1.65.0 in a 32 bit DLL. I use VS2005

 

When using ApplicationVerifier, I got application verifier stops due to leaked TLS slots.

 

The TLS slots are allocated in win_tss_ptr_create(). Each slot is wrapped into RAII class win_tss_ptr. The constructor allocates the TLS slot and the destructor de-allocates it.

I put printf-Statements in both methods and I see, that the constructor is called twice, while the destructor is not called at all. If I put a breakpoint into the destructor, it never triggers.

 

The printf() satemets show, that the following instances have been constructed:

 

boost::asio::detail::win_tss_ptr<class boost::asio::detail::call_stack<class boost::asio::detail::win_iocp_io_service,struct boost::asio::detail::win_iocp_thread_info>::context>::win_tss_ptr

boost::asio::detail::win_tss_ptr<class boost::asio::detail::call_stack<class boost::asio::detail::strand_service::strand_impl,unsigned char>::context>::win_tss_ptr

 

When I put a breakpoint into the constructor, I see, that both instances seem to be global variables

 

>             xxx.dll!boost::asio::detail::win_tss_ptr_create()  Line 40           C++

                xxx.dll!boost::asio::detail::win_tss_ptr<boost::asio::detail::call_stack<boost::asio::detail::win_iocp_io_service,boost::asio::detail::win_iocp_thread_info>::context>::win_tss_ptr<boost::asio::detail::call_stack<boost::asio::detail::win_iocp_io_service,boost::asio::detail::win_iocp_thread_info>::context>()  Line 42 + 0x3a bytes       C++

                xxx.dll!boost::asio::detail::tss_ptr<boost::asio::detail::call_stack<boost::asio::detail::win_iocp_io_service,boost::asio::detail::win_iocp_thread_info>::context>::tss_ptr<boost::asio::detail::call_stack<boost::asio::detail::win_iocp_io_service,boost::asio::detail::win_iocp_thread_info>::context>()  + 0xf bytes         C++

               xxx.dll!`dynamic initializer for 'boost::asio::detail::call_stack<boost::asio::detail::win_iocp_io_service,boost::asio::detail::win_iocp_thread_info>::top_''()  Line 165 + 0xd bytes      C++

               msvcr80d.dll!_initterm(void (void)* * pfbegin=0x101c43a0, void (void)* * pfend=0x101ce9c0)  Line 855           C

               xxx.dll!_CRT_INIT(void * hDllHandle=0x10000000, unsigned long dwReason=0x00000001, void * lpreserved=0x00000000)  Line 316 + 0xf bytes   C

               xxx.dll!__DllMainCRTStartup(void * hDllHandle=0x10000000, unsigned long dwReason=0x00000001, void * lpreserved=0x00000000)  Line 492 + 0x11 bytes               C

               xxx.dll!_DllMainCRTStartup(void * hDllHandle=0x10000000, unsigned long dwReason=0x00000001, void * lpreserved=0x00000000)  Line 462 + 0x11 bytes               C

 

Does anyone on this list has an idea, why the destructors aren’t called?

 

Thanks in advance,

 

Mario Klebsch

--

Mario Klebsch                      Actia I+ME GmbH

[hidden email]         Dresdenstrasse 17/18
Fon: +49 531 38 701 716            38124 Braunschweig
Fax: +49 531 38 701 88
            Germany

 


_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [asio] Boost-1.65.0 TlsSlot leak on win32

Boost - Users mailing list
On 20/03/2018 05:08, Klebsch, Mario wrote:

> I am using boost version 1.65.0 in a 32 bit DLL. I use VS2005
>
> When using ApplicationVerifier, I got application verifier stops due to
> leaked TLS slots.
>
> The TLS slots are allocated in win_tss_ptr_create(). Each slot is
> wrapped into RAII class win_tss_ptr. The constructor allocates the TLS
> slot and the destructor de-allocates it.
>
> I put printf-Statements in both methods and I see, that the constructor
> is called twice, while the destructor is not called at all. If I put a
> breakpoint into the destructor, it never triggers.

How is your process exiting?  Global destructors will only be called if
execution leaves main/WinMain normally (without calling terminate,
abort, _exit, TerminateProcess, throwing an exception, etc) -- and
they'll (silently) stop being called if any destructor does throw an
exception.

Also, unless you are dynamically unloading and reloading the DLL (and
dynamically unloading the DLL should trigger the destructors), a *small*
TLS slot leak is not that important as they are destroyed when your
process exits anyway -- despite annoying AppVerifier.  The main thing
the checks are there for are if you are leaking TLS slots each time you
call a particular method or something.

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [asio] Boost-1.65.0 TlsSlot leak on win32

Boost - Users mailing list
Hi,

> How is your process exiting?  Global destructors will only be called
> if execution leaves main/WinMain normally (without calling terminate,
> abort, _exit, TerminateProcess, throwing an exception, etc) -- and
> they'll (silently) stop being called if any destructor does throw an
> exception.

The process does not terminate. It just unloads the DLL.

> Also, unless you are dynamically unloading and reloading the DLL

That is what I (and our customer) is doing.

> (and dynamically unloading the DLL should trigger the destructors),

That is what I think, too.

I found, that _CRT_INIT() is called on load time to execute the constructors of global instances and that it is also called on unload time to execute destructors for global instances.

I put a breakpoint into the loop calling the destructors at unload time, and stepped into each of them. I found a lot of global destructors called, some for my global instances, others for boost::asio and other boost internal instances. But the destructor for those two win_tss_ptr<> instances does not seem to be in the list of destructors to call. :-(


> a *small* TLS slot leak is not that important as they are destroyed
> when your process exits anyway -- despite annoying AppVerifier.  The
> main thing the checks are there for are if you are leaking TLS slots
> each time you call a particular method or something.

Our customer recently had a problem caused by a TLS slot leak in an old version of boost::thread. The customers application stopped working after about 50 minutes, just because a single TLS slot leaked on each library unload.

73, Mario



_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users