From 8049520e1af0d370b981bf05ed540f0c566a57dd Mon Sep 17 00:00:00 2001
From: "leonard.beck" <leonard.beck@etu.hesge.ch>
Date: Mon, 24 May 2021 19:32:17 +0200
Subject: [PATCH] fixed leaks

---
 one_armed_bandit.c | 7 ++++++-
 wheel.h            | 4 ++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/one_armed_bandit.c b/one_armed_bandit.c
index 50d7db9..0c6d7bc 100644
--- a/one_armed_bandit.c
+++ b/one_armed_bandit.c
@@ -40,7 +40,7 @@ int stopped_wheels(machine mas){
 
 int main()
 {
-	int wheel_turn = 4;
+	int wheel_turn = WHEEL_NB + 1;
 	bool paid = false;
 	bool quit=false;
 	pthread_t threads[WHEEL_NB + 1];
@@ -114,5 +114,10 @@ int main()
 			}
 		} while(!quit);
 
+		sem_destroy(&(mas.semaphore));
+		for (int i = 0; i < WHEEL_NB; i++) {
+			pthread_mutex_destroy(&(mas.wheels[i].lock));
+		}
+
 		return 0;
 }
diff --git a/wheel.h b/wheel.h
index 0f39617..89b84e0 100644
--- a/wheel.h
+++ b/wheel.h
@@ -12,9 +12,9 @@ typedef struct roue{
   int current_px;
   // used to synchronize cache with memory so display is always up to date
   pthread_mutex_t lock;
-
+  // used to make the thread wait when the wheel is not spinning
   sem_t* semaphore;
-
+  // used to securely exit the game
   bool* end;
 
 } wheel;
-- 
GitLab