From: Lukas Jiriste Date: Thu, 28 Mar 2024 11:01:32 +0000 (+0100) Subject: Fix allocation of wrong size X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=f953d9b45c3890bc80ec78da053f614e1aa7e6a5;p=42%2Fphilosophers.git Fix allocation of wrong size The way the allocation was written, it allocated space for pointer instead of the structure pointed to. This has been corrected. --- diff --git a/philo/mem_management.c b/philo/mem_management.c index 6ac0713..49b3b6d 100644 --- a/philo/mem_management.c +++ b/philo/mem_management.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/28 09:39:55 by ljiriste #+# #+# */ -/* Updated: 2024/03/28 10:49:03 by ljiriste ### ########.fr */ +/* Updated: 2024/03/28 12:01:03 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,13 +22,13 @@ int init(t_diner *diner, pthread_t **threads) const size_t count = diner->setting.philo_count; size_t i; - diner->philos = malloc(sizeof(diner->philos) * count); - diner->forks = malloc(sizeof(diner->forks) * count); - *threads = malloc(sizeof(*threads) * count); - if (!diner->philos || !diner->forks || !*threads) - return (1); init_mutex(&diner->setting.terminal_lock, NULL); init_mutex(&diner->setting.end_lock, NULL); + diner->philos = malloc(sizeof(*diner->philos) * count); + diner->forks = malloc(sizeof(*diner->forks) * count); + *threads = malloc(sizeof(**threads) * count); + if (!diner->philos || !diner->forks || !*threads) + return (1); i = 0; while (i < count) {