In C, please review these codes,
static char* test = NULL;
typedef struct
{
char* member1;
}TestStruct;
void testCode()
{
TestStruct ts;
test = malloc(10*sizeof(char));
ts.member1 = test;
free(test);
}
1) Is this free code correct?
2) The allocated memory check task is on the heap, right?
3) is the test located in .bss?
4) if the testCode () function can be called in the stream, the test is one, right? but every time the thread calls testCode (), the test will be assigned a new pointer and there will be a memory leak, right? So, can I use this code to avoid it?
Mutex_Start
if(test == NULL)
test = malloc(10*sizeof(char));
Mutex_End
Please help me.
source
share