From fbe58b7b1433933d946750cf683f727ddfa4bc73 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 26 Feb 2016 18:41:04 +0300 Subject: [PATCH] WiFiClientSecure: don't panic if memory allocation fails If it fails due to a malloc somewhere in bigint.c, we will still crash (although with a less obvious crash message). If it fails in increase_bm_data_size, axTLS will handle this and report that connection has been aborted. This error will be passed on to the user, so that an application can recover and attempt to reconnect. --- libraries/ESP8266WiFi/src/WiFiClientSecure.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp b/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp index 118687eaf..ab0999ae4 100644 --- a/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp +++ b/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp @@ -532,10 +532,8 @@ extern "C" int ax_get_file(const char *filename, uint8_t **buf) { extern "C" void* ax_port_malloc(size_t size, const char* file, int line) { void* result = malloc(size); - if (result == nullptr) { DEBUG_TLS_MEM_PRINT("%s:%d malloc %d failed, left %d\r\n", file, line, size, ESP.getFreeHeap()); - panic(); } if (size >= 1024) { DEBUG_TLS_MEM_PRINT("%s:%d malloc %d, left %d\r\n", file, line, size, ESP.getFreeHeap()); @@ -553,7 +551,6 @@ extern "C" void* ax_port_realloc(void* ptr, size_t size, const char* file, int l void* result = realloc(ptr, size); if (result == nullptr) { DEBUG_TLS_MEM_PRINT("%s:%d realloc %d failed, left %d\r\n", file, line, size, ESP.getFreeHeap()); - panic(); } if (size >= 1024) { DEBUG_TLS_MEM_PRINT("%s:%d realloc %d, left %d\r\n", file, line, size, ESP.getFreeHeap()); @@ -563,9 +560,4 @@ extern "C" void* ax_port_realloc(void* ptr, size_t size, const char* file, int l extern "C" void ax_port_free(void* ptr) { free(ptr); - uint32_t *p = (uint32_t*) ptr; - size_t size = p[-3]; - if (size >= 1024) { - DEBUG_TLS_MEM_PRINT("free %d, left %d\r\n", p[-3], ESP.getFreeHeap()); - } }