Heap corruption on socket write or send
Posted: Tue Aug 27, 2019 4:05 am
I have noticed that sometimes, socket has problems allocating memory and creates an overflow, sometimes it happens randomly and then it works other times, it happens in two different random scenarios when I try to write to a socket or send to a socket.
This is the code I use:
I defined two tasks in the app_main.c
The first task runs perfectly however the second one sometimes in this line cannot continue:
s is a socket var, req is a pointer with dynamic value (this value is correctly filled)
This is the code I use:
I defined two tasks in the app_main.c
Code: Select all
xTaskCreate(&beat_task, "one_task", 2048, NULL, 4, NULL);
ESP_ERROR_CHECK( heap_trace_init_standalone(trace_record, NUM_RECORDS) );
xTaskCreate(&suitch_task, "two_task", 2048, NULL, 5, NULL);
s is a socket var, req is a pointer with dynamic value (this value is correctly filled)
Code: Select all
ESP_ERROR_CHECK( heap_trace_start(HEAP_TRACE_LEAKS) );
if (write(s, req, strlen(req)) < 0) {<<<<<problem here
ESP_LOGE(TAG, "... socket send failed");
close(s);
vTaskDelay(4000 / portTICK_PERIOD_MS);
continue;
}