version sans erreurs de valgrind autre que trois leaks

This commit is contained in:
Hugo LAMY
2019-06-01 13:47:21 +02:00
parent 04a4fef38b
commit 56ca478503
5 changed files with 43 additions and 6 deletions

View File

@@ -6,7 +6,7 @@
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;

View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View File

@@ -6,7 +6,7 @@
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
/*

21
main.c
View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}