From 44b6a9605781f9785c9f30a3c73b86d55f02755f Mon Sep 17 00:00:00 2001 From: Thomas Rieg Date: Mon, 8 Dec 2025 15:57:49 +0100 Subject: [PATCH] moved the memset for perturb patern back into the lock in the free function --- srcs/ft_free.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/srcs/ft_free.c b/srcs/ft_free.c index cf8cadf..9f1fedb 100644 --- a/srcs/ft_free.c +++ b/srcs/ft_free.c @@ -6,7 +6,7 @@ /* By: thrieg < thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/11/19 15:44:05 by thrieg #+# #+# */ -/* Updated: 2025/12/08 15:53:31 by thrieg ### ########.fr */ +/* Updated: 2025/12/08 15:57:17 by thrieg ### ########.fr */ /* */ /* ************************************************************************** */ @@ -104,7 +104,7 @@ void free(void *ptr) pthread_mutex_unlock(&g_mut); return; // we didn't allocate this ptr } - pthread_mutex_unlock(&g_mut); 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 + ft_memset(ptr, g_state.patern ^ 0xFF, header->size); // need to lock because this memory can be reallocated from another thread at any time (even before this function returns if we put it outside of lock) + pthread_mutex_unlock(&g_mut); }