added support for MALLOC_PERTURB_ environment variable

This commit is contained in:
Thomas Rieg 2025-12-08 15:48:24 +01:00
parent 0fd85cf568
commit 6d84b2f72a
17 changed files with 453 additions and 404 deletions

View file

@ -6,7 +6,7 @@
/* By: thrieg < thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/17 15:02:55 by thrieg #+# #+# */
/* Updated: 2025/11/25 14:30:44 by thrieg ### ########.fr */
/* Updated: 2025/12/08 15:37:27 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,6 +15,8 @@
void *malloc(size_t size)
{
pthread_mutex_lock(&g_mut);
if (!g_state.is_init)
init_env_variables();
if (!size || size % ALLIGN_BYTES)
size = ((size / ALLIGN_BYTES) + 1) * ALLIGN_BYTES;
void *ret = NULL;
@ -31,5 +33,7 @@ void *malloc(size_t size)
ret = add_tiny(size);
}
pthread_mutex_unlock(&g_mut);
if (g_state.patern)
ft_memset(ret, g_state.patern, size); // doesn't need to lock because we only modify the user pointer and the user doesn't have accces to it yet
return (ret);
}