removed leaks

This commit is contained in:
Theo Champion 2025-06-25 18:08:19 +02:00
parent c1484d2d3c
commit 2c009b5469
10 changed files with 67 additions and 31 deletions

View file

@ -1,10 +1,12 @@
CC=cc
SANITIZERS=-fsanitize=address -fno-omit-frame-pointer
SANITIZERS=
#-fsanitize=address -fno-omit-frame-pointer
CFLAGS=-Wall -Wextra -Werror -ggdb $(SANITIZERS) -I mlx
SOURCEFILES=src/main.c \
src/map/map_checker.c \
src/map/checkers.c \
src/map/setters.c
src/map/setters.c \
src/utils/frees.c
OBJECTS=$(patsubst src/%.c,objects/%.o,$(SOURCEFILES))
OBJDIR=objects
NAME=cub3d

View file

@ -6,7 +6,7 @@
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/06/21 19:34:43 by tchampio #+# #+# */
/* Updated: 2025/06/21 19:47:07 by tchampio ### ########.fr */
/* Updated: 2025/06/25 17:57:24 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -43,5 +43,6 @@ int copy_old_map(t_mapdata *map, char **newmap,
void add_map_line(const char *line, t_mapdata *map);
void print_map(char **map);
bool check_cubfile(char *file, t_mapdata *map);
void free_map(t_mapdata *map);
#endif

View file

@ -6,13 +6,15 @@
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/06/21 19:46:20 by tchampio #+# #+# */
/* Updated: 2025/06/24 11:47:02 by tchampio ### ########.fr */
/* Updated: 2025/06/25 17:52:35 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef STRUCTS_H
# define STRUCTS_H
# include <stdbool.h>
typedef struct s_mlx_data
{
void *img;

0
objects/utils/.gitkeep Normal file
View file

View file

@ -6,7 +6,7 @@
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/06 13:16:11 by tchampio #+# #+# */
/* Updated: 2025/06/24 11:50:17 by tchampio ### ########.fr */
/* Updated: 2025/06/25 18:07:40 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -45,37 +45,25 @@ void draw_2d_wall(unsigned int color, t_mlx_data *data,
}
}
void free_tab(char **tab)
int destroy(t_cub3d_data *data)
{
int i;
if (!tab)
return ;
i = 0;
while (tab[i])
{
free(tab[i]);
i++;
}
free(tab);
}
int destroy(t_mapdata *map)
{
free_tab(map->map);
free_tab(map->mapflood);
free(map->ea_texture);
free(map->no_texture);
free(map->so_texture);
free(map->we_texture);
free(map->filename);
free_map(data->map);
if (data->mlx_win)
mlx_destroy_window(data->mlx, data->mlx_win);
if (data->mlx_data)
mlx_destroy_image(data->mlx, data->mlx_data->img);
free(data->mlx_data);
if (data->mlx)
mlx_destroy_display(data->mlx);
free(data->mlx);
exit(0);
return 0;
}
int key_destroy(int keycode, t_mapdata *map)
int key_destroy(int keycode, t_cub3d_data *data)
{
if (keycode == 65307)
destroy(map);
destroy(data);
return (0);
}
@ -111,11 +99,12 @@ int main(int argc, char **argv)
return (ft_printf("Error: Wrong map file. Reason: %s\n", data.map->error), 1);
data.mlx = mlx_init();
data.mlx_win = mlx_new_window(data.mlx, 800, 600, "Cub3d");
data.mlx_data = ft_calloc(sizeof(t_mlx_data), 1);
data.mlx_data->img = mlx_new_image(data.mlx, 800, 600);
data.mlx_data->addr = mlx_get_data_addr(data.mlx_data->img, &data.mlx_data->bits_per_pixel, &data.mlx_data->line_length, &data.mlx_data->endian);
mlx_hook(data.mlx_win, 17, 0L, destroy, data.map);
mlx_hook(data.mlx_win, 17, 0L, destroy, &data);
draw_map(data.map, data.mlx_data);
mlx_key_hook(data.mlx_win, key_destroy, data.map);
mlx_key_hook(data.mlx_win, key_destroy, &data);
mlx_put_image_to_window(data.mlx, data.mlx_win, data.mlx_data->img, 0, 0);
mlx_loop(data.mlx);
}

42
src/utils/frees.c Normal file
View file

@ -0,0 +1,42 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* frees.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/06/25 17:46:01 by tchampio #+# #+# */
/* Updated: 2025/06/25 18:01:29 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../includes/cub3d_consts.h"
#include "../../includes/structs.h"
#include <stdlib.h>
void free_tab(char **tab)
{
int i;
if (!tab)
return ;
i = 0;
while (tab[i])
{
free(tab[i]);
i++;
}
free(tab);
}
void free_map(t_mapdata *map)
{
free_tab(map->map);
free_tab(map->mapflood);
free(map->ea_texture);
free(map->no_texture);
free(map->so_texture);
free(map->we_texture);
free(map->filename);
free(map);
}

BIN
vgcore.124879 Normal file

Binary file not shown.

BIN
vgcore.127690 Normal file

Binary file not shown.

BIN
vgcore.142306 Normal file

Binary file not shown.

BIN
vgcore.142888 Normal file

Binary file not shown.