I allocated some large chunks of memory through malloc
and aligned_alloc
, and then I setup a fence to a region inside the memory with size of one page size, using mprotect
:
void *buf = malloc(128 * PAGE_SIZE);
int ret = mprotect(buf, PAGE_SIZE, PROT_NONE);
Now I'm done with the memory and is calling free(buf);
to release it, my questions is do I need to reset mprotect
before calling free
, like this:
ret = mprotect(buf, PAGE_SIZE, PROT_READ|PROT_WRITE);
free(buf);
Or should I just do free
? I read that glibc will sometimes reuse some of the previously allocated memory, so if this region of memory is returned to later malloc
, will accessing it cause problems(since it's PROT_NONE
)?