Fix double free
authorLukas Jiriste <ljiriste@student.42prague.com>
Sun, 7 Jul 2024 07:18:47 +0000 (09:18 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Sun, 21 Jul 2024 18:21:21 +0000 (20:21 +0200)
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.

ft_parse/ft_parsing_table_generate.c

index 82329388e530f7cfe58754d7cbbdb2701c2e06ec..fc6092035b9a13e17f39fc1fe3fbdadbedba5e9e 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   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);