This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: TI-RTOS
Hello,
I allocated dynamic memory to a variable using the malloc().
And then I wanted to free the memory after use. So I used the free(). But then after that when I try to access the variable, I still get the value there, it is not freed.
char *temp = malloc(10 * sizeof(char));
.........Some code here to assign value to temp........
free(temp);
printf(temp) -> Here it still shows up the value
Is the free() not working then?
Regards,
Shyam
Hello!
That is correct behaviour. Call to free() marks relevant memory block as unused in heap internals, but free makes no attempt to invalidate the pointer you used in your application, or somehow clear memory block being freed. Its up to programmer to invalidate the pointer. If your application is sensitive to what was left in freed memory block, that again is responsibility of the user to clean it.
Hope this helps.