From: Dominik Kaiser Date: Sat, 18 Jan 2025 10:34:04 +0000 (+0100) Subject: Fix wrong allocation size X-Git-Url: https://git.dkaiser.de/?a=commitdiff_plain;h=b351d6471aa7fda52a45ea8c93308eb91aec7f32;p=42%2FPhilosophers.git Fix wrong allocation size --- diff --git a/philo/src/main.c b/philo/src/main.c index 0043e04..ca339bb 100644 --- a/philo/src/main.c +++ b/philo/src/main.c @@ -6,7 +6,7 @@ /* By: dkaiser nbr_of_philos); if (*philos == NULL) return (ft_err(ERR_MALLOC)); - data->forks = (t_fork *)malloc(sizeof(int) * data->nbr_of_philos); + data->forks = (t_fork *)malloc(sizeof(t_fork) * data->nbr_of_philos); if (data->forks == NULL) { free(*philos); @@ -55,7 +56,9 @@ int init(t_philo **philos, t_phdata *data) (*philos)[i].times_eaten = 0; (*philos)[i].data = data; data->forks[i].available = 1; - pthread_mutex_init(&(data->forks[i].mutex), NULL); + result = pthread_mutex_init(&(data->forks[i].mutex), NULL); + if (result != 0) + return (result); i++; } return (EXIT_SUCCESS); @@ -75,8 +78,8 @@ int main(int argc, char *argv[]) result = init(&philos, &data); if (result != EXIT_SUCCESS) return (result); - free(philos); run_simulation(data.nbr_of_philos, philos); + free(philos); free(data.forks); return (result); } diff --git a/philo/src/simulation.c b/philo/src/simulation.c index 011af9b..a30c7d2 100644 --- a/philo/src/simulation.c +++ b/philo/src/simulation.c @@ -6,13 +6,21 @@ /* By: dkaiser