22
33#include <limits.h>
44#include <stdio.h>
5+ #include <stdlib.h>
56
67#include "./sdl/main.h"
78
89int main () {
910 TGame game ;
1011
11- char dashboard [DASHBOARD_ROWS ][DASHBOARD_COLS ];
1212 int rows = DASHBOARD_ROWS ;
1313 int cols = DASHBOARD_COLS ;
14+ char * * dashboard = new2DArray (rows , cols );
1415
1516 char * requestedPattern ;
1617 char * maxGeneration ;
@@ -42,6 +43,8 @@ int main() {
4243
4344 drawPattern (& game , requestedPattern );
4445
46+ free (requestedPattern );
47+
4548 /* ----------------------- Request Maximum Generation ----------------------- */
4649
4750 maxGeneration = getUserInputStr (
@@ -51,12 +54,15 @@ int main() {
5154 sscanf (maxGeneration , "%d" , & maxGenerationInt );
5255
5356 if (maxGenerationInt < 0 ) {
57+ free (maxGeneration );
5458 maxGeneration = "infinity" ;
5559 maxGenerationInt = INT_MAX ;
5660 };
5761
5862 printf ("> Maximum generation received: %s.\n\n" , maxGeneration );
5963
64+ if (maxGenerationInt != INT_MAX ) free (maxGeneration );
65+
6066 /* ------------------------------ Request Delay ----------------------------- */
6167
6268 sprintf (delayBetweenGenerationsMsg ,
@@ -71,6 +77,8 @@ int main() {
7177
7278 printf ("> Delay received: %s milliseconds.\n\n" , delayBetweenGenerations );
7379
80+ free (delayBetweenGenerations );
81+
7482 /* ---------------------------- Request Platform ---------------------------- */
7583
7684 platformSelected = getUserInputStr (
@@ -81,11 +89,15 @@ int main() {
8189 printf ("> Platform selected: '%s'.\n" , platformSelected );
8290
8391 if (strcmpi (platformSelected , "console" ) == 0 ) {
92+ free (platformSelected );
8493 startGameByConsole (& game , maxGenerationInt , delayBetweenGenerationsInt );
94+ destroy2DArray (game .dashboard , game .rows , game .cols );
8595 return 0 ;
8696 }
8797
98+ free (platformSelected );
8899 startGameBySDL (& game , maxGenerationInt , delayBetweenGenerationsInt );
100+ destroy2DArray (game .dashboard , game .rows , game .cols );
89101
90102 return 0 ;
91103}
0 commit comments