Skip to content

OpenSSL memory leak without call to SSL_COMP_free_compression_methods #817

@jveazey

Description

@jveazey

I did this

`

/* Memory leak detecting */
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#define WIN32_LEAN_AND_MEAN 
#include <Windows.h>
#include <tchar.h>
#ifndef CURL_STATICLIB
#define CURL_STATICLIB
#endif
#include <curl/curl.h>
#pragma comment(lib, "libcurl_a.lib")

int _tmain(int argc, _TCHAR* argv[])
{
    _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE);
    _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR );
    _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE);
    _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR );
    _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE);
    _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR );
    _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );

    CURLcode output = curl_global_init(CURL_GLOBAL_ALL);
    curl_global_cleanup();

    _CrtDumpMemoryLeaks( );

    return 0;
}

`

It displayed the following

`

Detected memory leaks!
Dumping objects ->
{2966} normal block at 0x02499DF8, 16 bytes long.
 Data: <                > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
{2965} normal block at 0x024988F0, 20 bytes long.
 Data: <      I         > 00 00 00 00 F8 9D 49 02 01 00 00 00 04 00 00 00 
Object dump complete.

`

Possible fix

Calling SSL_COMP_free_compression_methods(); after curl_global_cleanup(); appears to fix the problem.

See also #2561: Memory leak with SSL built-in compressions

curl/libcurl version

curl 7.48.0 (i386-pc-win32) libcurl/7.48.0 OpenSSL/1.0.2h zlib/1.2.8 WinIDN
Protocols: dict file ftp ftps gopher http https imap imaps ldap pop3 pop3s rtsp smtp smtps telnet tftp
Features: AsynchDNS IDN IPv6 Largefile SSPI Kerberos SPNEGO NTLM SSL libz

operating system

Windows 10

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions