Skip to content

Commit a4a61ae

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 3070ca2 commit a4a61ae

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Release/src/http/client/http_client_winhttp.cpp

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

2929
#include "cpprest/details/http_client_impl.h"
3030

31+
// This is a hack to avoid memory leak reports from the debug MSVC CRT for all
32+
// programs using the library: ASIO calls SSL_library_init() which calls
33+
// SSL_COMP_get_compression_methods(), which allocates some heap memory and the
34+
// only way to free it later is to call SSL_COMP_free_compression_methods(),
35+
// but this function is unaccessible from the application code as OpenSSL is
36+
// statically linked into the C++ REST SDK DLL. So, just to be nice, call it
37+
// here ourselves -- even if the real problem is in ASIO (up to v1.60.0).
38+
#ifndef NDEBUG
39+
40+
#include <openssl/ssl.h>
41+
static struct ASIO_SSL_memory_leak_suppress
42+
{
43+
~ASIO_SSL_memory_leak_suppress()
44+
{
45+
::SSL_COMP_free_compression_methods();
46+
}
47+
} ASIO_SSL_memory_leak_suppressor;
48+
49+
#endif // NDEBUG
50+
3151
namespace web
3252
{
3353
namespace http

0 commit comments

Comments
 (0)