moved the memset for perturb patern back into the lock in the free function

This commit is contained in:
Thomas Rieg 2025-12-08 15:57:49 +01:00
parent 442063daae
commit 44b6a96057

View file

@ -6,7 +6,7 @@
/* By: thrieg < thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */ /* By: thrieg < thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/19 15:44:05 by thrieg #+# #+# */ /* 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); pthread_mutex_unlock(&g_mut);
return; // we didn't allocate this ptr return; // we didn't allocate this ptr
} }
pthread_mutex_unlock(&g_mut);
if (g_state.patern) 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);
} }