Opened 4 years ago

Last modified 3 years ago

#10795 new Bugs

Include asio/ssl/context.hpp reports two leaks on Windows

Reported by: Vinnie Falco <vinnie.falco@…> Owned by: chris_kohlhoff
Milestone: To Be Determined Component: asio
Version: Boost 1.57.0 Severity: Problem
Keywords: Cc:

Description

Simply including the header file <boost/asio/ssl/context.hpp> causes the Microsoft Visual Studio debug runtime (MSVCRTD library) to report two 32 byte leaks on exit. It is not clear if these are from asio or from OpenSSL. This sample program compiled for 64-bit Windows using Visual Studio 2013 demonstrates the problem:

#include <boost/asio/ssl/context.hpp>
#include <crtdbg.h>
int main()
{
    int flags = _CrtSetDbgFlag (_CRTDBG_REPORT_FLAG);
    flags |= _CRTDBG_LEAK_CHECK_DF;
    _CrtSetDbgFlag (flags);
}

This report is shown on exit, when main returns:

Detected memory leaks!
Dumping objects ->
{716} normal block at 0x00000000003953F0, 32 bytes long.
 Data: <                > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
{715} normal block at 0x00000000003952D0, 32 bytes long.
 Data: <         S9     > 00 00 00 00 CD CD CD CD F0 53 39 00 00 00 00 00 
Object dump complete.

Change History (3)

comment:1 Changed 3 years ago by vz-boost@…

I think it's the same bug that I reported in C++ REST SDK which uses ASIO: it's due to calling SSL_library_init() from openssl_init_base::do_init ctor but not calling SSL_COMP_free_compression_methods() anywhere.

comment:2 Changed 3 years ago by Vinnie Falco <vinnie.falco@…>

As a work-around, can a program just call SSL_COMP_free_compression_methods manually at the end of main? That would help reduce the volume of false positive leaks.

comment:3 Changed 3 years ago by vz-boost@…

This is unfortunately impossible when using C++ REST SDK, which is the whole reason for opening the above bug in the first place: it links to OpenSSL statically, so I can't work around the leak from outside it.

For now I've made an ugly patch fixing this there, but it would be clearly preferable to have the fix in ASIO itself.

Note: See TracTickets for help on using tickets.