Check for memory leaks
This commit is contained in:
parent
38197afd79
commit
05e347e80c
3
esp32_device/.vscode/settings.json
vendored
3
esp32_device/.vscode/settings.json
vendored
@ -33,6 +33,7 @@
|
|||||||
"esp_log.h": "c",
|
"esp_log.h": "c",
|
||||||
"http_client.h": "c",
|
"http_client.h": "c",
|
||||||
"string.h": "c",
|
"string.h": "c",
|
||||||
"cjson.h": "c"
|
"cjson.h": "c",
|
||||||
|
"stddef.h": "c"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,8 @@ void app_main(void)
|
|||||||
{
|
{
|
||||||
esp_log_level_set("*", ESP_LOG_VERBOSE);
|
esp_log_level_set("*", ESP_LOG_VERBOSE);
|
||||||
|
|
||||||
|
system_show_free_memory();
|
||||||
|
|
||||||
ESP_LOGI(TAG, "SolarEnergy WT32-ETH01 device");
|
ESP_LOGI(TAG, "SolarEnergy WT32-ETH01 device");
|
||||||
|
|
||||||
// Initialize storage
|
// Initialize storage
|
||||||
@ -101,6 +103,21 @@ void app_main(void)
|
|||||||
int status = secure_api_get_device_enrollment_status();
|
int status = secure_api_get_device_enrollment_status();
|
||||||
ESP_LOGI(TAG, "Current enrollment status: %d\n", status);
|
ESP_LOGI(TAG, "Current enrollment status: %d\n", status);
|
||||||
|
|
||||||
|
// Check for memory leaks
|
||||||
|
size_t before = system_show_free_memory();
|
||||||
|
for (int i = 0; i < 1000; i++)
|
||||||
|
{
|
||||||
|
char *buff = calloc(5000, 1);
|
||||||
|
assert(storage_get_dev_name(buff) > 0);
|
||||||
|
assert(storage_get_root_ca(buff) > 0);
|
||||||
|
free(crypto_get_csr());
|
||||||
|
// secure_api_get_device_enrollment_status();
|
||||||
|
printf("%d\n", i);
|
||||||
|
free(buff);
|
||||||
|
}
|
||||||
|
size_t after = system_show_free_memory();
|
||||||
|
printf("RES before = %d / after = %d / diff = %d\n", before, after, before - after);
|
||||||
|
|
||||||
system_sleep(120);
|
system_sleep(120);
|
||||||
|
|
||||||
reboot();
|
reboot();
|
||||||
|
@ -1,15 +1,25 @@
|
|||||||
#include "system.h"
|
#include "system.h"
|
||||||
|
|
||||||
|
#include "esp_log.h"
|
||||||
#include "esp_system.h"
|
#include "esp_system.h"
|
||||||
|
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
|
|
||||||
|
static const char *TAG = "system";
|
||||||
|
|
||||||
void system_sleep(size_t secs)
|
void system_sleep(size_t secs)
|
||||||
{
|
{
|
||||||
vTaskDelay((1000 * secs) / portTICK_PERIOD_MS);
|
vTaskDelay((1000 * secs) / portTICK_PERIOD_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t system_show_free_memory()
|
||||||
|
{
|
||||||
|
size_t v = heap_caps_get_free_size(MALLOC_CAP_DEFAULT);
|
||||||
|
ESP_LOGI(TAG, "heap_caps_free_size(MALLOC_CAP_DEFAULT) = %d", v);
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
void reboot()
|
void reboot()
|
||||||
{
|
{
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
@ -11,6 +11,11 @@ extern "C"
|
|||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get sum of free memory in chip
|
||||||
|
*/
|
||||||
|
size_t system_show_free_memory();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sleep for a given amount of time
|
* Sleep for a given amount of time
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user