From 56ca478503a27991d1f5bc0cb87b44fac455133b Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Sat, 1 Jun 2019 13:47:21 +0200 Subject: [PATCH 1/2] version sans erreurs de valgrind autre que trois leaks --- f_bonus_opti.c | 20 ++++++++++++++++++-- f_parse_input.c | 2 +- f_search_map.c | 2 +- fillit.h | 4 +++- main.c | 21 ++++++++++++++++++++- 5 files changed, 43 insertions(+), 6 deletions(-) diff --git a/f_bonus_opti.c b/f_bonus_opti.c index 21b4873..70d361f 100644 --- a/f_bonus_opti.c +++ b/f_bonus_opti.c @@ -6,7 +6,7 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/05/24 14:42:46 by hulamy #+# #+# */ -/* Updated: 2019/05/28 17:00:32 by hulamy ### ########.fr */ +/* Updated: 2019/06/01 13:46:56 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -51,6 +51,21 @@ int compare_tetri(t_fillist *tetri_a, t_fillist *tetri_b) return (1); } +/* +** Function that free the list->memory each time it's malloc +*/ + +t_fillist *clean_list_memory(t_fillist *list, t_fillist *tmp) +{ + while (tmp) + { + if (tmp->memory) + free(tmp->memory); + tmp = tmp->next; + } + return (list); +} + /* ** Test optimisation for not testing wrong maps when tetri are identical */ @@ -61,7 +76,8 @@ int check_same_tetri(t_fillist *list, int num) t_fillist *next_tetri; int i; - curr_tetri = list; + curr_tetri = clean_list_memory(list, list); +// curr_tetri = list; while (curr_tetri != NULL) { i = 0; diff --git a/f_parse_input.c b/f_parse_input.c index dd58683..5b90a63 100644 --- a/f_parse_input.c +++ b/f_parse_input.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */ -/* Updated: 2019/05/28 19:05:05 by hulamy ### ########.fr */ +/* Updated: 2019/06/01 13:32:38 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/f_search_map.c b/f_search_map.c index 836f819..00bb44e 100644 --- a/f_search_map.c +++ b/f_search_map.c @@ -6,7 +6,7 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/27 20:47:22 by hulamy #+# #+# */ -/* Updated: 2019/05/29 16:23:03 by hulamy ### ########.fr */ +/* Updated: 2019/06/01 13:38:26 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/fillit.h b/fillit.h index a73a692..984b987 100644 --- a/fillit.h +++ b/fillit.h @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */ -/* Updated: 2019/05/29 13:31:37 by vmanzoni ### ########.fr */ +/* Updated: 2019/06/01 13:44:51 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -94,6 +94,7 @@ int print_flags_usage(void); */ int check_same_tetri(t_fillist *list, int num); int compare_tetri(t_fillist *tetri_a, t_fillist *tetri_b); +t_fillist *clean_list_memory(t_fillist *list, t_fillist *tmp); int check_tetri_memory(t_fillist *list, int pos); /* @@ -101,6 +102,7 @@ int check_tetri_memory(t_fillist *list, int pos); */ int main(int argc, char **argv); int *create_dope(char *av, int mdp); +void clean_list(t_fillist *list, t_fillist *tmp); int is_mdp(int ac, char **av); /* diff --git a/main.c b/main.c index 5cf1d0c..c1f6a82 100644 --- a/main.c +++ b/main.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/02/12 13:20:48 by vmanzoni #+# #+# */ -/* Updated: 2019/05/29 13:27:14 by vmanzoni ### ########.fr */ +/* Updated: 2019/06/01 13:41:46 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -66,6 +66,22 @@ int is_mdp(int ac, char **av) return (1); } +/* +** Function that free the list +*/ + +void clean_list(t_fillist *list, t_fillist *tmp) +{ + tmp = list; + while (list) + { + list = tmp->next; + free(tmp->memory); + free(tmp); + tmp = list; + } +} + /* ** Main function */ @@ -87,8 +103,11 @@ int main(int ac, char **av) check_file_errors(input, dope); size = parse_input(input, &list, dope); print_final_map(list, size); + free(input); + clean_list(list, list); } else print_error("usage: Please submit a file.\n> ./fillit file.fillit\n"); + free(dope); return (0); } From f79d3812d0e35c57594b5a1887a8046936052434 Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Sat, 1 Jun 2019 13:57:39 +0200 Subject: [PATCH 2/2] il ne reste qu'un seul leaks --- f_bonus_opti.c | 2 +- f_print.c | 3 ++- main.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/f_bonus_opti.c b/f_bonus_opti.c index 70d361f..41e132f 100644 --- a/f_bonus_opti.c +++ b/f_bonus_opti.c @@ -6,7 +6,7 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/05/24 14:42:46 by hulamy #+# #+# */ -/* Updated: 2019/06/01 13:46:56 by hulamy ### ########.fr */ +/* Updated: 2019/06/01 13:47:51 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/f_print.c b/f_print.c index 219514f..d5ab0d2 100644 --- a/f_print.c +++ b/f_print.c @@ -6,7 +6,7 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/30 13:24:28 by hulamy #+# #+# */ -/* Updated: 2019/05/27 19:47:11 by hulamy ### ########.fr */ +/* Updated: 2019/06/01 13:56:50 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -99,6 +99,7 @@ void print_letter_map(t_fillist *list, int size, int flag) } } ft_putchar('\n'); + free(map); } /* diff --git a/main.c b/main.c index c1f6a82..494c3cf 100644 --- a/main.c +++ b/main.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/02/12 13:20:48 by vmanzoni #+# #+# */ -/* Updated: 2019/06/01 13:41:46 by hulamy ### ########.fr */ +/* Updated: 2019/06/01 13:51:37 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */