From baa49f0f8d0475475e142b416c6830f18f8bd4aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Nut=CC=A6iu?= Date: Sun, 11 Dec 2016 16:51:22 +0200 Subject: [PATCH] Freeing resources --- extra/DSA/matrix-cube.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/extra/DSA/matrix-cube.c b/extra/DSA/matrix-cube.c index 9dae0e0..260fa1e 100644 --- a/extra/DSA/matrix-cube.c +++ b/extra/DSA/matrix-cube.c @@ -158,6 +158,7 @@ void print_matrix(unsigned ** testM) { } } +// This function will create a new matrix. unsigned ** new_matrix(unsigned row, unsigned col) { unsigned ** mat = (unsigned **) calloc(row, sizeof(unsigned *)); if (mat == NULL) { @@ -169,6 +170,14 @@ unsigned ** new_matrix(unsigned row, unsigned col) { 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 // will start the labyrinth. unsigned solve_mat(unsigned c, unsigned r) { @@ -328,6 +337,7 @@ int main(void) { print_matrix(testM); } + destroy_matrix(testM); config_destroy(&configuration); return EXIT_SUCCESS; }