File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -196,7 +196,7 @@ void* malloc(size_t len) {
196196}
197197
198198
199- /* The wrapper for free(). This simply marks the entire region as PROT_NONE.
199+ /* The wrapper for free().
200200 If the region is already freed, the code will segfault during the attempt to
201201 read the canary. Not very graceful, but works, right? */
202202
@@ -214,15 +214,9 @@ void free(void* ptr) {
214214
215215 total_mem -= len ;
216216
217- /* Protect everything. Note that the extra page at the end is already
218- set as PROT_NONE, so we don't need to touch that. */
219-
220217 ptr -= PAGE_SIZE * PG_COUNT (len + 8 ) - len - 8 ;
221218
222- if (mprotect (ptr - 8 , PG_COUNT (len + 8 ) * PAGE_SIZE , PROT_NONE ))
223- FATAL ("mprotect() failed when freeing memory" );
224-
225- /* Keep the mapping; this is wasteful, but prevents ptr reuse. */
219+ munmap (ptr - 8 , (1 + PG_COUNT (len + 8 )) * PAGE_SIZE );
226220
227221}
228222
You can’t perform that action at this time.
0 commit comments