Skip to content

WiFiClientSecure does not free memory after a failed connection. #4335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
VoLinhTruc opened this issue Sep 12, 2020 · 2 comments
Closed

WiFiClientSecure does not free memory after a failed connection. #4335

VoLinhTruc opened this issue Sep 12, 2020 · 2 comments
Labels
Status: Stale Issue is stale stage (outdated/stuck)

Comments

@VoLinhTruc
Copy link
Contributor

VoLinhTruc commented Sep 12, 2020

Hardware:

Board: ESP32 Dev Module
Core Installation version: 1.0.3
IDE name: Platform.io
Flash Frequency: 80Mhz
PSRAM enabled: no
Upload Speed: 115200
Computer OS: Windows 10

Description:

WiFiClientSecure does not free memory after a failed connection.

Update: In the ssl_client.cpp, in start_ssl_client function.

if (rootCABuff != NULL) {
        log_v("Loading CA cert");
        mbedtls_x509_crt_init(&ssl_client->ca_cert);
        mbedtls_ssl_conf_authmode(&ssl_client->ssl_conf, MBEDTLS_SSL_VERIFY_REQUIRED);
        ret = mbedtls_x509_crt_parse(&ssl_client->ca_cert, (const unsigned char *)rootCABuff, strlen(rootCABuff) + 1);
        mbedtls_ssl_conf_ca_chain(&ssl_client->ssl_conf, &ssl_client->ca_cert, NULL);
        //mbedtls_ssl_conf_verify(&ssl_client->ssl_ctx, my_verify, NULL );
        if (ret < 0) {
            return handle_error(ret);
        }
    }

You can see that after mbedtls_x509_crt_init(&ssl_client->ca_cert);,
if (ret < 0) has no mbedtls_x509_crt_free(&ssl_client->ca_cert); to free memory.
So the free memory in RAM decreasing continuously.

The same thing (I guess) may occur with the

ret = mbedtls_x509_crt_parse(&ssl_client->client_cert, (const unsigned char *)cli_cert, strlen(cli_cert) + 1);
if (ret < 0) {
       return handle_error(ret);
}

and the

ret = mbedtls_pk_parse_key(&ssl_client->client_key, (const unsigned char *)cli_key, strlen(cli_key) + 1, NULL, 0);

if (ret != 0) {
     return handle_error(ret);
}

So please update the code. My project is stuck here. I need your help.
Thank you so much.

Sketch:

void loop() {
  // put your main code here, to run repeatedly:

  Serial.println(esp_get_free_heap_size());

  WiFiClientSecure client;
  client.setCACert(test_root_ca);
  client.setCertificate(client_crt);
  client.setPrivateKey(client_key);

  Serial.println(client.connect("test.mosquitto.org", 8884, 500));
  client.stop();

}

Serial Monitor:

WiFi connected.
IP address:
192.168.1.37
213744
0
206964
0
201252
0
195012
0
189440
0
183204
0
175860
0
171924
0
165688
0
160332
0
155072
0
149676
0
142304
0
138484
0
133096
0
125940
0
121700
0
115892
0
110076
0
104268
0
98340
0
93076
0
87148
0
81472
0
75868
0
69728
0
64468
0
58868
0
59020
0
59020
0
59020
0
53064
0
53220
0
53220
0
53220
0
53220
0
53220
0
53220
0
53220
0
53428
0
53428
0
53428
0
53428
0
47680
0
41748
0
36280
0
30352
0
30836
0
30836

VoLinhTruc added a commit to VoLinhTruc/arduino-esp32 that referenced this issue Oct 13, 2020
I met problem while I was working with the WiFiClientSecure.
I tried to found the source of the problem, and I found it in the sll_client.cpp.
Please check my contribution.

I've open this problem in espressif#4335 but received no response.
me-no-dev pushed a commit that referenced this issue Oct 14, 2020
I met problem while I was working with the WiFiClientSecure.
I tried to found the source of the problem, and I found it in the sll_client.cpp.
Please check my contribution.

I've open this problem in #4335 but received no response.
@stale
Copy link

stale bot commented Nov 13, 2020

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Stale Issue is stale stage (outdated/stuck) label Nov 13, 2020
@stale
Copy link

stale bot commented Nov 27, 2020

[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.

@stale stale bot closed this as completed Nov 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Stale Issue is stale stage (outdated/stuck)
Projects
None yet
Development

No branches or pull requests

1 participant