added support for MALLOC_PERTURB_ environment variable
This commit is contained in:
parent
0fd85cf568
commit
6d84b2f72a
17 changed files with 453 additions and 404 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: thrieg < thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/11/19 15:44:05 by thrieg #+# #+# */
|
||||
/* Updated: 2025/11/25 16:21:10 by thrieg ### ########.fr */
|
||||
/* Updated: 2025/12/08 15:34:11 by thrieg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -65,6 +65,8 @@ int defrag_zone(t_zone *zone)
|
|||
void free(void *ptr)
|
||||
{
|
||||
pthread_mutex_lock(&g_mut);
|
||||
if (!g_state.is_init)
|
||||
init_env_variables(); // shouldn't ever happen because free can't be called first, but it protects the program
|
||||
if (!ptr)
|
||||
return ((void)pthread_mutex_unlock(&g_mut));
|
||||
t_header *header = ((t_header *)ptr) - 1;
|
||||
|
|
@ -84,6 +86,8 @@ void free(void *ptr)
|
|||
void *ptr = header->zone;
|
||||
size_t len = header->zone->size;
|
||||
munmap(ptr, len);
|
||||
pthread_mutex_unlock(&g_mut);
|
||||
return;
|
||||
}
|
||||
else if (header->zone->type == E_SMALL)
|
||||
{
|
||||
|
|
@ -95,5 +99,12 @@ void free(void *ptr)
|
|||
header->occupied = false;
|
||||
defrag_zone(header->zone);
|
||||
}
|
||||
else
|
||||
{
|
||||
pthread_mutex_unlock(&g_mut);
|
||||
return; // we didn't allocate this ptr
|
||||
}
|
||||
if (g_state.patern)
|
||||
ft_memset(ptr, g_state.patern ^ 0xFF, header->size); // doesn't need to lock because we only modify the user pointer and the user doesn't have accces to it yet
|
||||
pthread_mutex_unlock(&g_mut);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue