diff --git a/src/model.c b/src/model.c index ef7eed7..709c768 100644 --- a/src/model.c +++ b/src/model.c @@ -44,7 +44,6 @@ s_tictactoe *create_empty_tictactoe() { s_utictactoe *create_empty_utictactoe (uint inception_level) { s_utictactoe * value = (s_utictactoe*) malloc(sizeof(s_utictactoe)); if ( value ) { - // then initiate outer_tictactoe amd inception_level value->outer_tictactoe = create_empty_tictactoe(); value->inception_level = inception_level; @@ -59,13 +58,14 @@ s_utictactoe *create_empty_utictactoe (uint inception_level) { // should be 9 simple ttt value->inner_tictactoes = (s_tictactoe**) - malloc(sizeof(s_tictactoe)); - + malloc(TICTACTOE_SIZE*sizeof(s_tictactoe)); + if ( ! value->inner_tictactoes ) { return NULL; } for ( int i=0; iinner_tictactoes[i]= (s_tictactoe*) malloc(sizeof(s_tictactoe)); value->inner_tictactoes[i] = create_empty_tictactoe(); } } @@ -75,14 +75,16 @@ s_utictactoe *create_empty_utictactoe (uint inception_level) { void free_move(s_move *p_move){ - if ( p_move == NULL ) { + if ( p_move ) { free(p_move); + p_move = NULL; } } void free_tictactoe(s_tictactoe *p_ttt){ if ( p_ttt) { free(p_ttt->content); + p_ttt->content = NULL; free(p_ttt); p_ttt = NULL; } @@ -96,6 +98,7 @@ void free_utictactoe(s_utictactoe *p_uttt){ free_tictactoe(p_uttt->inner_tictactoes[i]); } free(p_uttt->inner_tictactoes); + p_uttt->inner_tictactoes = NULL; } free_tictactoe(p_uttt->outer_tictactoe); free(p_uttt);