I have a variable declared as const char *. I have allocated memory for that using malloc(). After using it, I want to free that memory using free(). But I am not able to do that and it gives me error that “Attempting to write to protected memory”. How do I free the memory allocated?
Thanks,
Rakesh.
If you’re getting that error then you’re doing something wrong and you’ll need to post the code so we can figure out what it is. For what it’s worth, you can free a
const char*as evidenced in the following code, which compiles and executes perfectly: