From 27afcbe7e9863bc97205a3b021235e78863863b7 Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Sat, 1 Jun 2019 12:36:34 +0200 Subject: [PATCH] tentative d'enlever les leaks en cours --- f_bonus_opti.c | 7 ++++--- f_bonus_print.c | 27 +++++++++++++-------------- f_parse_input.c | 3 ++- f_print.c | 3 ++- f_search_map.c | 13 +++++-------- fillit.h | 10 +++++----- main.c | 3 ++- 7 files changed, 33 insertions(+), 33 deletions(-) diff --git a/f_bonus_opti.c b/f_bonus_opti.c index 21b4873..4e10d81 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 12:31:29 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,6 +25,7 @@ int check_tetri_memory(t_fillist *list, int pos) mask = 1 << ((pos % 32) - 1); if (tetri->same) { +// ft_putstr("tetri->same->memory"); ft_putstr((char *)tetri->same->memory); ft_putstr(" -- "); ft_putnbrendl(pos / 32); if (!(tetri->same->memory[pos / 32] & mask)) return (tetri->same->memory[pos / 32] |= mask); } @@ -65,7 +66,7 @@ int check_same_tetri(t_fillist *list, int num) while (curr_tetri != NULL) { i = 0; - if (!(curr_tetri->memory = + if (!curr_tetri->memory && !(curr_tetri->memory = (unsigned int *)malloc(sizeof(*curr_tetri->memory) * num))) return (0); while (i < num) @@ -81,5 +82,5 @@ int check_same_tetri(t_fillist *list, int num) curr_tetri->total_num = num; curr_tetri = curr_tetri->next; } - return (0); + return (1); } diff --git a/f_bonus_print.c b/f_bonus_print.c index ad0b195..0637048 100644 --- a/f_bonus_print.c +++ b/f_bonus_print.c @@ -6,7 +6,7 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/05/27 13:46:29 by hulamy #+# #+# */ -/* Updated: 2019/05/29 16:25:52 by hulamy ### ########.fr */ +/* Updated: 2019/05/29 18:31:22 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,33 +16,31 @@ ** function that print the given tetris if flag p is present */ -t_fillist *print_tetri(t_fillist *list) +int print_tetri(t_fillist *list, int size) { unsigned int print; - t_fillist *tmp; - tmp = list; if (list->dope[2]) { - while (tmp) + while (list && ++size) { check_same_tetri(list, 1); - print = tmp->tetribit; + print = list->tetribit; print <<= 16; - print_sized_map(&print, tmp->width, tmp->height, tmp->letter); - if (tmp->same && list->dope[1]) + print_sized_map(&print, list->width, list->height, list->letter); + if (list->same && list->dope[1]) { - print = tmp->same->tetribit; + print = list->same->tetribit; print <<= 16; ft_putstr("same --> "); - ft_put_tetri_color(tmp->same->letter); + ft_put_tetri_color(list->same->letter); ft_putchar('\n'); } ft_putchar('\n'); - tmp = tmp->next; + list = list->next; } } - return (list); + return (size); } /* @@ -50,7 +48,7 @@ t_fillist *print_tetri(t_fillist *list) ** it returns anyway the size of the map for main to print it */ -int print_binary_map(unsigned int *map, int size, int *dope) +int print_binary_map(unsigned int *map, int size, int *dope) { size--; if (dope[2]) @@ -59,6 +57,7 @@ int print_binary_map(unsigned int *map, int size, int *dope) print_sized_map(map, size, size, '#'); ft_putchar('\n'); } + free(map); return (size); } @@ -66,7 +65,7 @@ int print_binary_map(unsigned int *map, int size, int *dope) ** function that print the flags usage */ -int print_flags_usage(void) +int print_flags_usage(void) { ft_putendl("flags usage :"); ft_putendl("d : debug print (print the map during the backtracking)"); diff --git a/f_parse_input.c b/f_parse_input.c index dd58683..3c9db91 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/05/29 19:08:15 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -121,6 +121,7 @@ int add_to_list(char *line, t_fillist **lst, char letter, int *dope) tmp->letter = letter; tmp->dope = dope; tmp->start = *lst; + tmp->memory = NULL; return (1); } diff --git a/f_print.c b/f_print.c index 219514f..cc4a781 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/05/29 19:10:33 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -98,6 +98,7 @@ void print_letter_map(t_fillist *list, int size, int flag) ft_putchar(' '); } } + free(map); ft_putchar('\n'); } diff --git a/f_search_map.c b/f_search_map.c index 836f819..3faf377 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/05/29 18:28:04 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -141,17 +141,13 @@ int fill_map(unsigned int *map, t_fillist *list, int size) int search_map(t_fillist *list) { - t_fillist *tmp; - unsigned int *map = NULL; + unsigned int *map; int size; int num; int i; size = 2; - num = 1; - tmp = print_tetri(list); - while ((tmp = tmp->next)) - num++; + num = print_tetri(list, 0); while (size * size < num * 4) size++; i = 0; @@ -164,7 +160,8 @@ int search_map(t_fillist *list) while (num--) map[num] = 0; i = fill_map(map, list, size++); + if (!i) + free(map); } - free(map); return (print_binary_map(map, size, list->dope)); } diff --git a/fillit.h b/fillit.h index a73a692..9d5cc01 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 12:27:09 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -55,7 +55,7 @@ ** place : position sur l'axe des abscisses de la map (position % size) ** rank : position de 1 a 32 dans l'int du tableau d'int (position % 32) ** num : memorise dans quel int du tableau on se trouve (position / 32) -** test : +** test : to print the tetri during the backtracking, test is a boolean ** letter : letter of the tetrimino for printing final map ** dope : flags for details, optimisation, printing and error ** memory : positions already tested by a tetrimino in bitwise @@ -85,16 +85,16 @@ typedef struct s_fillist /* ** bonus_print.c */ -t_fillist *print_tetri(t_fillist *list); +int print_tetri(t_fillist *list, int size); int print_binary_map(unsigned int *map, int size, int *dope); int print_flags_usage(void); /* ** bonus_opti.c */ -int check_same_tetri(t_fillist *list, int num); -int compare_tetri(t_fillist *tetri_a, t_fillist *tetri_b); int check_tetri_memory(t_fillist *list, int pos); +int compare_tetri(t_fillist *tetri_a, t_fillist *tetri_b); +int check_same_tetri(t_fillist *list, int num); /* ** main.c diff --git a/main.c b/main.c index 5cf1d0c..91eea81 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/05/29 19:09:11 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -87,6 +87,7 @@ int main(int ac, char **av) check_file_errors(input, dope); size = parse_input(input, &list, dope); print_final_map(list, size); + free(input); } else print_error("usage: Please submit a file.\n> ./fillit file.fillit\n");