regler leak dans exit
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* ft_arraylen.c :+: :+: :+: */
|
/* array.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: yantoine <yantoine@student.42.fr> +#+ +:+ +#+ */
|
/* By: yantoine <yantoine@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/17 21:10:10 by yantoine #+# #+# */
|
/* Created: 2025/02/17 21:10:10 by yantoine #+# #+# */
|
||||||
/* Updated: 2025/02/17 21:21:30 by yantoine ### ########.fr */
|
/* Updated: 2025/02/25 18:46:02 by yantoine ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: yantoine <yantoine@student.42.fr> +#+ +:+ +#+ */
|
/* By: yantoine <yantoine@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/14 01:41:17 by yantoine #+# #+# */
|
/* Created: 2025/02/14 01:41:17 by yantoine #+# #+# */
|
||||||
/* Updated: 2025/02/25 17:52:55 by yantoine ### ########.fr */
|
/* Updated: 2025/02/25 19:05:30 by yantoine ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -34,10 +34,39 @@ static inline t_scene parsing_line(char *line, t_scene scene)
|
|||||||
return (scene);
|
return (scene);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char **get_all_file(int fd)
|
||||||
|
{
|
||||||
|
char *join;
|
||||||
|
char *line;
|
||||||
|
char *data;
|
||||||
|
char **splited;
|
||||||
|
int first;
|
||||||
|
|
||||||
|
first = 1;
|
||||||
|
line = NULL;
|
||||||
|
data = ft_calloc(1, 1);
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
if (!first)
|
||||||
|
data = join;
|
||||||
|
line = get_next_line(fd);
|
||||||
|
if (!line)
|
||||||
|
break ;
|
||||||
|
join = ft_strjoin(data, line);
|
||||||
|
free(line);
|
||||||
|
free(data);
|
||||||
|
first = 0;
|
||||||
|
}
|
||||||
|
splited = ft_split(join, '\n');
|
||||||
|
free(data);
|
||||||
|
return (splited);
|
||||||
|
}
|
||||||
|
|
||||||
// ----- Parsing du fichier de configuration -----
|
// ----- Parsing du fichier de configuration -----
|
||||||
t_scene load_config(const char *filename)
|
t_scene load_config(const char *filename)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
int i;
|
||||||
char *line;
|
char *line;
|
||||||
t_scene scene;
|
t_scene scene;
|
||||||
|
|
||||||
@@ -49,9 +78,11 @@ t_scene load_config(const char *filename)
|
|||||||
return (scene);
|
return (scene);
|
||||||
}
|
}
|
||||||
scene.fd_if_exit = fd;
|
scene.fd_if_exit = fd;
|
||||||
while (1)
|
scene.all_file = get_all_file(fd);
|
||||||
|
i = -1;
|
||||||
|
while (scene.all_file[++i])
|
||||||
{
|
{
|
||||||
line = get_next_line(fd);
|
line = scene.all_file[i];
|
||||||
if (!line)
|
if (!line)
|
||||||
break ;
|
break ;
|
||||||
scene = parsing_line(line, scene);
|
scene = parsing_line(line, scene);
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_realloc.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: yantoine <yantoine@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/02/25 17:58:34 by yantoine #+# #+# */
|
||||||
|
/* Updated: 2025/02/25 18:06:12 by yantoine ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "miniRT.h"
|
||||||
|
|
||||||
|
static void *allocate_memory(size_t new_size)
|
||||||
|
{
|
||||||
|
void *new_ptr;
|
||||||
|
|
||||||
|
new_ptr = malloc(new_size);
|
||||||
|
if (!new_ptr)
|
||||||
|
return (NULL);
|
||||||
|
return (new_ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void copy_memory(void *dst, void *src, size_t size)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (i < size)
|
||||||
|
{
|
||||||
|
((char *)dst)[i] = ((char *)src)[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static size_t get_copy_size(size_t old_size, size_t new_size)
|
||||||
|
{
|
||||||
|
if (old_size < new_size)
|
||||||
|
return (old_size);
|
||||||
|
return (new_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *ft_realloc(void *ptr, size_t old_size, size_t new_size)
|
||||||
|
{
|
||||||
|
void *new_ptr;
|
||||||
|
size_t copy_size;
|
||||||
|
|
||||||
|
if (new_size == 0)
|
||||||
|
{
|
||||||
|
free(ptr);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
new_ptr = allocate_memory(new_size);
|
||||||
|
if (!new_ptr)
|
||||||
|
return (NULL);
|
||||||
|
if (ptr)
|
||||||
|
{
|
||||||
|
copy_size = get_copy_size(old_size, new_size);
|
||||||
|
copy_memory(new_ptr, ptr, copy_size);
|
||||||
|
free(ptr);
|
||||||
|
}
|
||||||
|
return (new_ptr);
|
||||||
|
}
|
||||||
+1
-1
Submodule libft updated: 2b3e413e15...17b5a6fdc0
@@ -6,7 +6,7 @@
|
|||||||
/* By: yantoine <yantoine@student.42.fr> +#+ +:+ +#+ */
|
/* By: yantoine <yantoine@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/13 20:02:36 by yantoine #+# #+# */
|
/* Created: 2025/02/13 20:02:36 by yantoine #+# #+# */
|
||||||
/* Updated: 2025/02/25 00:34:07 by yantoine ### ########.fr */
|
/* Updated: 2025/02/25 18:35:45 by yantoine ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -132,6 +132,7 @@ typedef struct s_scene
|
|||||||
int num_ambient;
|
int num_ambient;
|
||||||
char *line_if_exit;
|
char *line_if_exit;
|
||||||
char **token_if_exit;
|
char **token_if_exit;
|
||||||
|
char **all_file;
|
||||||
int fd_if_exit;
|
int fd_if_exit;
|
||||||
} t_scene;
|
} t_scene;
|
||||||
|
|
||||||
@@ -286,4 +287,7 @@ void print_ambient(t_ambient amb);
|
|||||||
void print_camera(t_camera cam);
|
void print_camera(t_camera cam);
|
||||||
void print_scene(t_scene scene);
|
void print_scene(t_scene scene);
|
||||||
|
|
||||||
|
// Memoire
|
||||||
|
void *ft_realloc(void *ptr, \
|
||||||
|
size_t old_size, size_t new_size);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+4
-1
@@ -6,7 +6,7 @@
|
|||||||
/* By: yantoine <yantoine@student.42.fr> +#+ +:+ +#+ */
|
/* By: yantoine <yantoine@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/17 19:22:27 by yantoine #+# #+# */
|
/* Created: 2025/02/17 19:22:27 by yantoine #+# #+# */
|
||||||
/* Updated: 2025/02/25 15:38:46 by yantoine ### ########.fr */
|
/* Updated: 2025/02/25 19:06:52 by yantoine ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -22,6 +22,7 @@ int key_press(int keycode, t_app *app)
|
|||||||
mlx_destroy_window(app->mlx, app->win);
|
mlx_destroy_window(app->mlx, app->win);
|
||||||
mlx_destroy_display(app->mlx);
|
mlx_destroy_display(app->mlx);
|
||||||
free(app->mlx);
|
free(app->mlx);
|
||||||
|
free(app->scene.all_file);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
@@ -35,6 +36,8 @@ int handle_close(void *param)
|
|||||||
mlx_destroy_image(app->mlx, app->img);
|
mlx_destroy_image(app->mlx, app->img);
|
||||||
mlx_destroy_window(app->mlx, app->win);
|
mlx_destroy_window(app->mlx, app->win);
|
||||||
mlx_destroy_display(app->mlx);
|
mlx_destroy_display(app->mlx);
|
||||||
|
ft_free_array(app->scene.all_file);
|
||||||
|
free(app->scene.all_file);
|
||||||
free(app->mlx);
|
free(app->mlx);
|
||||||
exit(0);
|
exit(0);
|
||||||
return (0);
|
return (0);
|
||||||
|
|||||||
@@ -269,6 +269,8 @@ all makefile /^all: $(NAME)$/;" t
|
|||||||
all minilibx-linux/Makefile /^all : do_configure$/;" t
|
all minilibx-linux/Makefile /^all : do_configure$/;" t
|
||||||
all minilibx-linux/Makefile.mk /^all : $(NAME)$/;" t
|
all minilibx-linux/Makefile.mk /^all : $(NAME)$/;" t
|
||||||
all minilibx-linux/test/Makefile.mk /^all: $(NAME)$/;" t
|
all minilibx-linux/test/Makefile.mk /^all: $(NAME)$/;" t
|
||||||
|
all_file miniRT.h /^ char **all_file;$/;" m struct:s_scene typeref:typename:char **
|
||||||
|
allocate_memory ft_realloc.c /^static void *allocate_memory(size_t new_size)$/;" f typeref:typename:void * file:
|
||||||
ambient miniRT.h /^ t_ambient ambient;$/;" m struct:s_scene typeref:typename:t_ambient
|
ambient miniRT.h /^ t_ambient ambient;$/;" m struct:s_scene typeref:typename:t_ambient
|
||||||
aspect miniRT.h /^ float aspect;$/;" m struct:s_calc typeref:typename:float
|
aspect miniRT.h /^ float aspect;$/;" m struct:s_calc typeref:typename:float
|
||||||
at_exit minilibx-linux/test/run_tests.sh /^at_exit() {$/;" f
|
at_exit minilibx-linux/test/run_tests.sh /^at_exit() {$/;" f
|
||||||
@@ -322,6 +324,7 @@ color_map_2 minilibx-linux/test/main.c /^int color_map_2(unsigned char *data,int
|
|||||||
compute_cap_intersection parsing_cylinder_utils.c /^void compute_cap_intersection(t_ray ray, t_cylinder cy, t_calc *calc)$/;" f typeref:typename:void
|
compute_cap_intersection parsing_cylinder_utils.c /^void compute_cap_intersection(t_ray ray, t_cylinder cy, t_calc *calc)$/;" f typeref:typename:void
|
||||||
compute_hit_normal parsing_cylinder_utils.c /^void compute_hit_normal(t_ray ray, t_cylinder cy, t_calc *calc,$/;" f typeref:typename:void
|
compute_hit_normal parsing_cylinder_utils.c /^void compute_hit_normal(t_ray ray, t_cylinder cy, t_calc *calc,$/;" f typeref:typename:void
|
||||||
compute_side_intersection parsing_cylinder_utils.c /^void compute_side_intersection(t_cylinder cy, t_calc *calc)$/;" f typeref:typename:void
|
compute_side_intersection parsing_cylinder_utils.c /^void compute_side_intersection(t_cylinder cy, t_calc *calc)$/;" f typeref:typename:void
|
||||||
|
copy_memory ft_realloc.c /^static void copy_memory(void *dst, void *src, size_t size)$/;" f typeref:typename:void file:
|
||||||
count_word libft/ft_split.c /^static size_t count_word(char *str, char c)$/;" f typeref:typename:size_t file:
|
count_word libft/ft_split.c /^static size_t count_word(char *str, char c)$/;" f typeref:typename:size_t file:
|
||||||
counter libft/libft.h /^ size_t counter;$/;" m struct:s_info typeref:typename:size_t
|
counter libft/libft.h /^ size_t counter;$/;" m struct:s_info typeref:typename:size_t
|
||||||
cp miniRT.h /^ t_vec3 cp;$/;" m struct:s_calc typeref:typename:t_vec3
|
cp miniRT.h /^ t_vec3 cp;$/;" m struct:s_calc typeref:typename:t_vec3
|
||||||
@@ -391,7 +394,7 @@ ft_putchar_fd libft/ft_putchar_fd.c /^void ft_putchar_fd(char c, int fd)$/;" f t
|
|||||||
ft_putendl_fd libft/ft_putendl_fd.c /^void ft_putendl_fd(char *s, int fd)$/;" f typeref:typename:void
|
ft_putendl_fd libft/ft_putendl_fd.c /^void ft_putendl_fd(char *s, int fd)$/;" f typeref:typename:void
|
||||||
ft_putnbr_fd libft/ft_putnbr_fd.c /^void ft_putnbr_fd(int n, int fd)$/;" f typeref:typename:void
|
ft_putnbr_fd libft/ft_putnbr_fd.c /^void ft_putnbr_fd(int n, int fd)$/;" f typeref:typename:void
|
||||||
ft_putstr_fd libft/ft_putstr_fd.c /^void ft_putstr_fd(char *s, int fd)$/;" f typeref:typename:void
|
ft_putstr_fd libft/ft_putstr_fd.c /^void ft_putstr_fd(char *s, int fd)$/;" f typeref:typename:void
|
||||||
ft_realloc libft/ft_realloc.c /^void *ft_realloc(void *ptr, size_t new_size)$/;" f typeref:typename:void *
|
ft_realloc ft_realloc.c /^void *ft_realloc(void *ptr, size_t old_size, size_t new_size)$/;" f typeref:typename:void *
|
||||||
ft_set_digit libft/ft_itoa.c /^static void ft_set_digit(long nbr_digit, long index, char *nbr, long n)$/;" f typeref:typename:void file:
|
ft_set_digit libft/ft_itoa.c /^static void ft_set_digit(long nbr_digit, long index, char *nbr, long n)$/;" f typeref:typename:void file:
|
||||||
ft_set_digit libft/ft_putnbr_fd.c /^static void ft_set_digit(long nbr_digit, long n, int fd)$/;" f typeref:typename:void file:
|
ft_set_digit libft/ft_putnbr_fd.c /^static void ft_set_digit(long nbr_digit, long n, int fd)$/;" f typeref:typename:void file:
|
||||||
ft_set_number libft/ft_itoa.c /^static void ft_set_number(char *tab)$/;" f typeref:typename:void file:
|
ft_set_number libft/ft_itoa.c /^static void ft_set_number(char *tab)$/;" f typeref:typename:void file:
|
||||||
@@ -416,6 +419,8 @@ ft_toupper libft/ft_toupper.c /^int ft_toupper(int c)$/;" f typeref:typename:int
|
|||||||
gc minilibx-linux/mlx_int.h /^ GC gc;$/;" m struct:s_win_list typeref:typename:GC
|
gc minilibx-linux/mlx_int.h /^ GC gc;$/;" m struct:s_win_list typeref:typename:GC
|
||||||
gc minilibx-linux/mlx_int.h /^ GC gc;$/;" m struct:s_img typeref:typename:GC
|
gc minilibx-linux/mlx_int.h /^ GC gc;$/;" m struct:s_img typeref:typename:GC
|
||||||
gere_mouse minilibx-linux/test/new_win.c /^int gere_mouse(int x,int y,int button,void*toto)$/;" f typeref:typename:int
|
gere_mouse minilibx-linux/test/new_win.c /^int gere_mouse(int x,int y,int button,void*toto)$/;" f typeref:typename:int
|
||||||
|
get_all_file config.c /^static char **get_all_file(int fd)$/;" f typeref:typename:char ** file:
|
||||||
|
get_copy_size ft_realloc.c /^static size_t get_copy_size(size_t old_size, size_t new_size)$/;" f typeref:typename:size_t file:
|
||||||
get_next_line libft/gnl.c /^char *get_next_line(int fd)$/;" f typeref:typename:char *
|
get_next_line libft/gnl.c /^char *get_next_line(int fd)$/;" f typeref:typename:char *
|
||||||
get_tokens_secure parsing_utils.c /^char **get_tokens_secure(t_scene scene, const int numObject,$/;" f typeref:typename:char **
|
get_tokens_secure parsing_utils.c /^char **get_tokens_secure(t_scene scene, const int numObject,$/;" f typeref:typename:char **
|
||||||
get_xlib_include_path minilibx-linux/configure /^get_xlib_include_path(){$/;" f
|
get_xlib_include_path minilibx-linux/configure /^get_xlib_include_path(){$/;" f
|
||||||
|
|||||||
Reference in New Issue
Block a user