Feb 06, 2023
01:06 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Feb 06, 2023
01:06 AM
Hi there,
I'm trying to use the free() function, but it causes __asm__ volatile ("debug" : : : "memory"); .
There will not be error, when I put malloc() and free() into same function, like:
However, when it sperate to two functions, it will have error, like:
May I know why? Thank you!
Best Regards,
Leon
Solved! Go to Solution.
1 Solution
Feb 06, 2023
10:44 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Feb 06, 2023
10:44 PM
If you access the *ptr after free(), it may lead error.
2 Replies
Feb 06, 2023
08:39 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Feb 06, 2023
08:39 PM
#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"
#include "SPI_CPU.h"
#include "Ifx_Fifo.h"
#include <stdlib.h>
#include "_Utilities/Ifx_Assert.h"
#include "Cpu/Std/IfxCpu.h"
#include "Stm/Std/IfxStm.h"
IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;
uint16 *receivePtr;
void readData_Long(uint16 addr, uint16 length){
uint16 i;
receivePtr=(uint16*)malloc(length *sizeof(uint16));
for(i=0;i<length;i++)
*(receivePtr+i)=i+1;
}
void get_readData_Long(uint16 data[],uint16 length){
uint16 i;
for(i=0;i<length;i++)
{
data[i]=*(receivePtr+i);
}
free(receivePtr);
}
void core0_main(void)
{
uint16 data[11];
IfxCpu_enableInterrupts();
/* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
* Enable the watchdogs and service them periodically if it is required
*/
IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());
/* Wait for CPU sync event */
IfxCpu_emitEvent(&g_cpuSyncEvent);
IfxCpu_waitEvent(&g_cpuSyncEvent, 1);
readData_Long(0,10);
get_readData_Long(data,10);
while(1)
{
}
}
Please refer to above code, there is no error found.
Feb 06, 2023
10:44 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Feb 06, 2023
10:44 PM
If you access the *ptr after free(), it may lead error.
This widget could not be displayed.