From 2664a23d7c05e089ab3dc9a23eeee8ecc75edbb5 Mon Sep 17 00:00:00 2001 From: Tsunghao Date: Fri, 30 Aug 2024 14:10:53 +0200 Subject: [PATCH] fixed leak issue in map_list. Ready to Merge --- includes/cub3d.h | 3 +-- srcs/game_init.c | 6 ++--- srcs/main.c | 3 +-- srcs/parser/build_map.c | 53 ++--------------------------------------- srcs/parser/parser.c | 3 +-- 5 files changed, 8 insertions(+), 60 deletions(-) diff --git a/includes/cub3d.h b/includes/cub3d.h index 0f18882..ff561c0 100644 --- a/includes/cub3d.h +++ b/includes/cub3d.h @@ -6,7 +6,7 @@ /* By: tsuchen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/15 00:19:44 by tsuchen #+# #+# */ -/* Updated: 2024/08/30 11:02:01 by tsuchen ### ########.fr */ +/* Updated: 2024/08/30 14:08:32 by tsuchen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -104,7 +104,6 @@ typedef struct s_data char *map_path; int map_fd; size_t map_bound; - // size_t map_start; char **map; void *mlx; void *window; diff --git a/srcs/game_init.c b/srcs/game_init.c index 472c8bf..38b189f 100644 --- a/srcs/game_init.c +++ b/srcs/game_init.c @@ -6,7 +6,7 @@ /* By: tsuchen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/27 17:03:43 by jteissie #+# #+# */ -/* Updated: 2024/08/29 19:06:27 by tsuchen ### ########.fr */ +/* Updated: 2024/08/30 14:08:48 by tsuchen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -44,8 +44,8 @@ int game_init(t_data *data) } if (load_assets(data) == PANIC) { - // cleanup(data); - // return (PANIC); + cleanup(data); + return (PANIC); } data->image.img = mlx_new_image(data->mlx, WIDTH, HEIGHT); data->image.addr = mlx_get_data_addr(data->image.img, &data->image.bpp, diff --git a/srcs/main.c b/srcs/main.c index b5602fd..b43239c 100644 --- a/srcs/main.c +++ b/srcs/main.c @@ -6,7 +6,7 @@ /* By: tsuchen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/15 12:03:33 by tsuchen #+# #+# */ -/* Updated: 2024/08/30 11:48:49 by tsuchen ### ########.fr */ +/* Updated: 2024/08/30 14:09:06 by tsuchen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -77,7 +77,6 @@ int main(int ac, char *av[]) return (EXIT_FAILURE); if (parse_map(&data) == PANIC) return (EXIT_FAILURE); - // print_data(&data); if (game_init(&data) == PANIC) return (EXIT_FAILURE); start_game(&data); diff --git a/srcs/parser/build_map.c b/srcs/parser/build_map.c index edde009..6e64030 100644 --- a/srcs/parser/build_map.c +++ b/srcs/parser/build_map.c @@ -6,7 +6,7 @@ /* By: tsuchen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/16 16:51:48 by jteissie #+# #+# */ -/* Updated: 2024/08/30 12:00:04 by tsuchen ### ########.fr */ +/* Updated: 2024/08/30 14:07:33 by tsuchen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,29 +25,6 @@ void panic_free(char **array) free(array); } -// static size_t get_map_size(char *path) -// { -// int fd; -// size_t line_nb; -// char *gnl_buff; - -// fd = open(path, O_RDONLY); -// if (fd < 0) -// return (0); -// gnl_buff = get_next_line(fd); -// if (!gnl_buff) -// return (0); -// line_nb = 1; -// while (gnl_buff) -// { -// free(gnl_buff); -// gnl_buff = get_next_line(fd); -// line_nb++; -// } -// close(fd); -// return (line_nb); -// } - static t_list *read_map_file(char *line, t_data *data) { t_list *map_list; @@ -65,7 +42,7 @@ static t_list *read_map_file(char *line, t_data *data) ft_lstclear(&map_list, free); return (NULL); } - ft_lstadd_back(&map_list, ft_lstnew(line)); + ft_lstadd_back(&map_list, new_node); } else free(line); @@ -74,32 +51,6 @@ static t_list *read_map_file(char *line, t_data *data) return (map_list); } -// static char **read_map_file(size_t size, char *line, t_data *data) -// { -// size_t index; -// char **map; - -// index = 0; -// map = ft_calloc(size + 1, sizeof(char *)); -// if (!map) -// return (NULL); -// while (line) -// { -// map[index] = ft_strdup(line); -// if (!map[index]) -// { -// free(line); -// panic_free(map); -// return (NULL); -// } -// free(line); -// line = get_next_line(data->map_fd); -// index++; -// } -// map[index] = NULL; -// return (map); -// } - char **build_map(t_data *data, char *line) { t_list *map_list; diff --git a/srcs/parser/parser.c b/srcs/parser/parser.c index ed76bba..201f9e1 100644 --- a/srcs/parser/parser.c +++ b/srcs/parser/parser.c @@ -6,7 +6,7 @@ /* By: tsuchen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/15 12:12:00 by tsuchen #+# #+# */ -/* Updated: 2024/08/30 11:46:42by tsuchen ### ########.fr */ +/* Updated: 2024/08/30 14:09:41 by tsuchen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -98,7 +98,6 @@ int parse_map(t_data *data) close(data->map_fd); if (!data->map) return (PANIC); - // print_parsed_map(data); if (verify_map(data->map, data) == MAP_ERR) { ft_putstr_fd("Error\n", STDERR_FILENO);