Skip to content

Commit

Permalink
Work around SSL compression methods memory leak in ASIO
Browse files Browse the repository at this point in the history
Call SSL_COMP_free_compression_methods() because ASIO itself doesn't, even
though it should, because it calls SSL_library_init() which allocates memory
for the compression methods.

Closes #67
  • Loading branch information
vadz committed May 6, 2016
1 parent 3070ca2 commit a4a61ae
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Release/src/http/client/http_client_winhttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@

#include "cpprest/details/http_client_impl.h"

// This is a hack to avoid memory leak reports from the debug MSVC CRT for all
// programs using the library: ASIO calls SSL_library_init() which calls
// SSL_COMP_get_compression_methods(), which allocates some heap memory and the
// only way to free it later is to call SSL_COMP_free_compression_methods(),
// but this function is unaccessible from the application code as OpenSSL is
// statically linked into the C++ REST SDK DLL. So, just to be nice, call it
// here ourselves -- even if the real problem is in ASIO (up to v1.60.0).
#ifndef NDEBUG

#include <openssl/ssl.h>
static struct ASIO_SSL_memory_leak_suppress
{
~ASIO_SSL_memory_leak_suppress()
{
::SSL_COMP_free_compression_methods();
}
} ASIO_SSL_memory_leak_suppressor;

#endif // NDEBUG

namespace web
{
namespace http
Expand Down

0 comments on commit a4a61ae

Please sign in to comment.