diff --git a/sources/ft_clean_struct.c b/sources/ft_clean_struct.c index a50cbab..6acd1e2 100644 --- a/sources/ft_clean_struct.c +++ b/sources/ft_clean_struct.c @@ -12,39 +12,55 @@ #include "push_swap.h" +/** + * Função auxiliar para limpar a lista encadeada +*/ static void ft_clean_list(t_stack **list) { t_stack *aux; t_stack *temp; aux = *list; + // Se a lista estiver vazia, não há nada a fazer if (aux == NULL) return ; while (aux != NULL) { temp = aux->next; + // Libera a memória alocada para o nó atual free(aux); aux = temp; } + // Define o ponteiro da lista como NULL para indicar que está vazia *list = NULL; } +/** + * Função para limpar a estrutura principal e arrays associados +*/ void ft_clean_project(t_stack_pack *pack, int *array_num, int *start_index, - char **array_bin) + char **array_bin) { int index; + // Libera a memória alocada para o array 'start_index' free(start_index); - // start_index = NULL; + // Libera a memória alocada para o array 'array_num' free(array_num); - // array_num = NULL; + + /* Chama a função para limpar a lista encadeada 'stack_a' + * dentro da estrutura 'pack' */ ft_clean_list(&pack->stack_a); + /* Chama a função para limpar a lista encadeada 'stack_b' + * dentro da estrutura 'pack' */ ft_clean_list(&pack->stack_b); index = 0; while (index < pack->length) { + // Libera a memória alocada para cada string no array 'array_bin' free(array_bin[index]); index++; } + // Libera a memória alocada para o array 'array_bin' free(array_bin); } diff --git a/sources/ft_make_binaries.c b/sources/ft_make_binaries.c index a97c677..3be1167 100644 --- a/sources/ft_make_binaries.c +++ b/sources/ft_make_binaries.c @@ -6,7 +6,7 @@ /* By: evportel +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/10/14 15:27:59 by evportel #+# #+# */ -/* Updated: 2023/10/15 15:28:01 by evportel ### ########.fr */ +/* Updated: 2023/10/18 20:05:36 by evportel ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,7 @@ * pode ser dividido por '2', antes de se tornar zero. * Será usado para determinar o tamanho da alocação de memória necessária. */ -static int ft_find_limit(int length) +int ft_find_limit(int length) { int limit;