Freeing resources

This commit is contained in:
Denis Nuțiu 2016-12-11 16:51:22 +02:00
parent d211265687
commit baa49f0f8d

View file

@ -158,6 +158,7 @@ void print_matrix(unsigned ** testM) {
} }
} }
// This function will create a new matrix.
unsigned ** new_matrix(unsigned row, unsigned col) { unsigned ** new_matrix(unsigned row, unsigned col) {
unsigned ** mat = (unsigned **) calloc(row, sizeof(unsigned *)); unsigned ** mat = (unsigned **) calloc(row, sizeof(unsigned *));
if (mat == NULL) { if (mat == NULL) {
@ -169,6 +170,14 @@ unsigned ** new_matrix(unsigned row, unsigned col) {
return mat; return mat;
} }
// This function will destroy the matrix.
void destroy_matrix(unsigned ** matrix) {
for (int i = 0; i < rows; ++i) {
free(testM[i]);
}
free(testM);
}
// This function will be called with the initial position from where the player // This function will be called with the initial position from where the player
// will start the labyrinth. // will start the labyrinth.
unsigned solve_mat(unsigned c, unsigned r) { unsigned solve_mat(unsigned c, unsigned r) {
@ -328,6 +337,7 @@ int main(void) {
print_matrix(testM); print_matrix(testM);
} }
destroy_matrix(testM);
config_destroy(&configuration); config_destroy(&configuration);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }