Skip to content

Commit 12619af

Browse files
committed
Work around SSL compression methods memory leak in ASIO
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
1 parent 1e0b5c5 commit 12619af

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Release/src/websockets/client/ws_client_wspp.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,26 @@
6262

6363
#endif /* __GNUC__ */
6464

65+
// This is a hack to avoid memory leak reports from the debug MSVC CRT for all
66+
// programs using the library: ASIO calls SSL_library_init() which calls
67+
// SSL_COMP_get_compression_methods(), which allocates some heap memory and the
68+
// only way to free it later is to call SSL_COMP_free_compression_methods(),
69+
// but this function is unaccessible from the application code as OpenSSL is
70+
// statically linked into the C++ REST SDK DLL. So, just to be nice, call it
71+
// here ourselves -- even if the real problem is in ASIO (up to v1.60.0).
72+
#if defined(_WIN32) && !defined(NDEBUG)
73+
74+
#include <openssl/ssl.h>
75+
static struct ASIO_SSL_memory_leak_suppress
76+
{
77+
~ASIO_SSL_memory_leak_suppress()
78+
{
79+
::SSL_COMP_free_compression_methods();
80+
}
81+
} ASIO_SSL_memory_leak_suppressor;
82+
83+
#endif /* _WIN32 && !NDEBUG */
84+
6585
using websocketpp::lib::placeholders::_1;
6686
using websocketpp::lib::placeholders::_2;
6787
using websocketpp::lib::bind;

0 commit comments

Comments
 (0)