I want to use asprintf for getting large string and dynamic allocation, but when i am using in my task, memory allocation gets failed.
and esp32 resets. what is wrong in my code?
Code: Select all
void producer_task(void *pvParameter){
char *mydata=NULL;
while(1){
vTaskDelay(10);
int ret=asprintf(&mydata,"abcdefghijklmnopqrstuvwxyzxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
if(ret==-1)
{
ESP_LOGI(tag, "asprintf:memory allocation failed");
}
ESP_LOGI(tag, "single_tag:%s", mydata);
if(xQueueSend( xQueue, ( void * )&mydata, ( portTickType )0 )==errQUEUE_FULL)
{
ESP_LOGI("Queue","Queue is full..");
}
mydata=NULL;
free(mydata);
}
}