use malloc, calloc and free memory occurred Hard fault interrupt. why?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-10-14 4:16 AM
Target: STM32G473RBTX
IDE: STM32CubeIDE v1.4.2
bool read(STRUCT *devInfo)
{
uint8_t readbuf[len];
STRUCT *tmp = (STRUCT *)calloc(1, sizeof( STRUCT ));
if(EEPRomReadNByte(addr, len, readbuf))
{
tmp = (STRUCT *)&readbuf; //implicit convert
memcpy(devInfo, tmp, sizeof( STRUCT ));//make sure
}
free(tmp); //<- HardFault_Handler occurred
}
1.why happened to call free memory will occur Hard fault interrupt?
2.implicit convert some time is work or not, why?
Labels:
- Labels:
-
STM32CubeIDE
-
STM32G4 Series
This discussion is locked. Please start a new topic to ask your question.
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-10-14 4:42 AM
You are trying to free memory that isn't part of the heap.
And the chaining structure contains random junk, which is undefined and unpredictable.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Up vote any posts that you find helpful, it shows what's working..
