diff --git a/includes/cub3d.h b/includes/cub3d.h index 43f0c4c..c74ec85 100644 --- a/includes/cub3d.h +++ b/includes/cub3d.h @@ -23,5 +23,6 @@ int keyrelease_handler(int keycode, t_cub3d_data *data); void my_mlx_pixel_put(t_mlx_data *data, int x, int y, int color); void draw_2d_wall(unsigned int color, t_mlx_data *data, int x, int y); void draw_map(t_mapdata *map, t_player *player, t_mlx_data *data); +void gnl_exhaust(int fd); #endif diff --git a/src/map/setters.c b/src/map/setters.c index 648e4be..1252b15 100644 --- a/src/map/setters.c +++ b/src/map/setters.c @@ -12,6 +12,7 @@ #include "../../includes/maputils.h" #include "../../includes/libft.h" +#include "../../includes/cub3d.h" unsigned long set_color(const char *s, t_mapdata *map) { @@ -79,7 +80,7 @@ bool add_textures(int fd, t_mapdata *map) while (line && set_lines < 6) { if (!set_textures(line, map)) - return (free(line), false); + return (free(line), gnl_exhaust(fd), false); else set_lines++; free(line); diff --git a/src/utils/frees.c b/src/utils/frees.c index 7290b09..f114c2e 100644 --- a/src/utils/frees.c +++ b/src/utils/frees.c @@ -3,16 +3,17 @@ /* ::: :::::::: */ /* frees.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: tchampio +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/06/25 17:46:01 by tchampio #+# #+# */ -/* Updated: 2025/07/15 10:26:48 by tchampio ### ########.fr */ +/* Created: 2025/07/17 13:59:27 by kcolin #+# #+# */ +/* Updated: 2025/07/17 14:00:01 by kcolin ### ########.fr */ /* */ /* ************************************************************************** */ #include "../../includes/cub3d_consts.h" #include "../../includes/structs.h" #include "../../mlx/mlx.h" +#include "../../includes/libft.h" #include void free_tab(char **tab) @@ -56,3 +57,19 @@ int destroy(t_cub3d_data *data) exit(0); return (0); } + +/* +Calls get_next_line in a loop until NULL is returned, freeing all data returned. +Ensures that all memory allocated by get_next_line is properly freed. +*/ +void gnl_exhaust(int fd) +{ + char *line; + + line = get_next_line(fd); + while (line != NULL) + { + free(line); + line = get_next_line(fd); + } +}