Skip to content

WiFiClientSecure: Memory leak when an SSL Handshake fails #5781

Closed
@Phsacar

Description

@Phsacar

Hardware:

Board: ESP32 Dev Module
Core Installation version: x
IDE name: Platform.io
Flash Frequency: 40Mhz
PSRAM enabled: no
Upload Speed: 115200
Computer OS: Ubuntu

Description:

Hi,
I found a leak in ssl_client.cpp:
If the Handshake fails in start_ssl_client(), and an error is returned, the following section is never reached:

  if (rootCABuff != NULL) {
        mbedtls_x509_crt_free(&ssl_client->ca_cert);
    }

    if (cli_cert != NULL) {
        mbedtls_x509_crt_free(&ssl_client->client_cert);
    }

    if (cli_key != NULL) {
        mbedtls_pk_free(&ssl_client->client_key);
    }   

There does not seem to be a deconstructor in WiFiClientSecure that handles freeing the memory either.

Background: I am using a CA to connect to an encrypted mqtt server; only after freeing ssl_client->ca_cert myself I stopped having memory leaks.

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