Skip to content

Commit

Permalink
fixed leak issue in map_list. Ready to Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Tsunghao-C committed Aug 30, 2024
1 parent 01e890a commit 2664a23
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 60 deletions.
3 changes: 1 addition & 2 deletions includes/cub3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: tsuchen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions srcs/game_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: tsuchen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions srcs/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: tsuchen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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);
Expand Down
53 changes: 2 additions & 51 deletions srcs/parser/build_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: tsuchen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions srcs/parser/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: tsuchen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2664a23

Please sign in to comment.