From: Lukas Jiriste Date: Sun, 7 Jul 2024 07:18:47 +0000 (+0200) Subject: Fix double free X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=d29fb2c45ea265da7890c962ab6f4d5f9773af40;p=Libft.git Fix double free Because the goto_tokens used tokens from table instead of their copies and were freed when generator states were cleared, the table tokens then contained pointers to freed memory which were to be used. There are two ways to fix this. Either not free the tokens in goto_tokens or append copies. I opted for the latter because every part of the generator code uses copies too. It may be rewritten to use the table tokens later on to save memory. --- diff --git a/ft_parse/ft_parsing_table_generate.c b/ft_parse/ft_parsing_table_generate.c index 8232938..fc60920 100644 --- a/ft_parse/ft_parsing_table_generate.c +++ b/ft_parse/ft_parsing_table_generate.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/27 11:16:53 by ljiriste #+# #+# */ -/* Updated: 2024/07/05 12:20:24 by ljiriste ### ########.fr */ +/* Updated: 2024/07/07 09:17:53 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -499,7 +499,7 @@ t_ft_stat solve_gotos(t_generator_state *state, t_vec *states, const t_vec *rule else ft_vec_free(&new_kernel, void_free_item); ft_vec_append(&state->goto_states, &state_num); - ft_vec_append(&state->goto_tokens, token); + append_token(&state->goto_tokens, token); } } return (success);