From f953d9b45c3890bc80ec78da053f614e1aa7e6a5 Mon Sep 17 00:00:00 2001 From: Lukas Jiriste Date: Thu, 28 Mar 2024 12:01:32 +0100 Subject: [PATCH] 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. --- philo/mem_management.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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) { -- 2.30.2