Geob-o-matic
Geob-o-matic

Reputation: 6079

FreeRTOS crash only in Release

I have this code that crash only in Release:

int main() 
{
  MyStruct s;
  s.field = bla;

  xTaskCreate(TestTask, "TestTask", 2000, &s, 1, 0);

  // other tasks creation
  vTaskStartScheduler();
}


void TestTask(void *p) 
{
  // some delay
  MyStruct* s = (MyStruct*)p;
  another_func(s->field); // hard fault
}

I manage to fix it like this:

int main()
{
  MyStruct* s = new MyStruct();
  s->field = bla;
  xTaskCreate(TestTask, "TestTask", 2000, s, 1, 0);

  // other tasks creation
  vTaskStartScheduler();
}

I don't understand why. Did I fixed it or workaround a memory corruption that can still be there?

Thanks.

Upvotes: 2

Views: 301

Answers (1)

Geob-o-matic
Geob-o-matic

Reputation: 6079

I'm so stupid, it's written on FreeRTOS' doc: https://www.freertos.org/a00125.html

so it is not valid to pass the address of a stack variable.

Upvotes: 3

Related Questions