diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-06 19:03:24 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-06 19:03:51 +0100 |
commit | a35b258841cde7884f5bb71d5ae0951d5e3f27b7 (patch) | |
tree | b7d1c6801ba924e129b3d008091a3f1b2e0adc95 | |
parent | Name is Cub3D anyway (diff) | |
download | 42-cub3d-a35b258841cde7884f5bb71d5ae0951d5e3f27b7.tar.gz 42-cub3d-a35b258841cde7884f5bb71d5ae0951d5e3f27b7.tar.bz2 42-cub3d-a35b258841cde7884f5bb71d5ae0951d5e3f27b7.tar.xz 42-cub3d-a35b258841cde7884f5bb71d5ae0951d5e3f27b7.tar.zst 42-cub3d-a35b258841cde7884f5bb71d5ae0951d5e3f27b7.zip |
fork(3) going well, freed a leak
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | inc/cub3d.h | 2 | ||||
-rw-r--r-- | map/lvl_one.cub | 2 | ||||
-rw-r--r-- | src/ft_exit.c | 3 | ||||
-rw-r--r-- | src/ft_music.c | 10 | ||||
-rw-r--r-- | src/ft_parse_map.c | 10 | ||||
-rw-r--r-- | src/ft_treat_args.c | 7 | ||||
-rw-r--r-- | src/ft_warp_level.c | 1 |
8 files changed, 24 insertions, 14 deletions
@@ -113,7 +113,8 @@ ifdef ASAN CFLAGS += ${FSANITIZE} endif #--------------------------------------------------------------------------------------------------# -CDEFS = -DFT_SCR_SIZE=\"${SCR_SZE}\" +CDEFS = -D_POSIX_C_SOURCE +CDEFS += -DFT_SCR_SIZE=\"${SCR_SZE}\" ifeq (${OS}, Darwin) CDEFS += -DFT_OS=1 else diff --git a/inc/cub3d.h b/inc/cub3d.h index 7b57942..ea55faf 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -119,7 +119,7 @@ uint8_t ft_use_args(int argc, const char *argv[], t_cub *clist); */ void ft_set_minimap_scale(t_cub *clist); -void *ft_music_thread(void *vargp); +void ft_music_fork(char *music_cmd); void ft_detect(t_cub *cl); void ft_castray(t_cub *cl); int8_t ft_save_to_bmp(t_cub *cl); diff --git a/map/lvl_one.cub b/map/lvl_one.cub index 330ffbc..c21c879 100644 --- a/map/lvl_one.cub +++ b/map/lvl_one.cub @@ -1,4 +1,4 @@ -R 1500 1000 +R 900 500 NO ./media/img/BRIQUASSE_3.xpm SO ./media/img/BRIQUASSE_3.xpm diff --git a/src/ft_exit.c b/src/ft_exit.c index c7b2275..3ba1237 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -15,6 +15,7 @@ #include <mlx.h> #include <stddef.h> #include <stdlib.h> +#include <signal.h> #include <stdint.h> static void @@ -65,7 +66,7 @@ int } if (clist->isoldmus && clist->wlist.inited) { - /* kill fork() here */ + kill(clist->mpid, SIGTERM); } ft_free_lists(clist); ft_printf("Exiting program\n"); diff --git a/src/ft_music.c b/src/ft_music.c index b9e9d89..70bb1a1 100644 --- a/src/ft_music.c +++ b/src/ft_music.c @@ -12,17 +12,19 @@ #include <libft.h> #include <cub3d.h> -#include <stddef.h> #include <stdlib.h> +#include <unistd.h> + void - ft_music_fork(t_cub *cl) + ft_music_fork(char *music_cmd) { - cl->isoldmus = 1; + (void)music_cmd; while (1) { ft_printf("qweqwe\n"); + sleep(1); } - /* system(cl->mlist.music_cmd); */ /* execve here */ + /* system(cl->mlist.music_cmd); */ } diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c index 3c1fd9c..36d1ec5 100644 --- a/src/ft_parse_map.c +++ b/src/ft_parse_map.c @@ -75,13 +75,13 @@ static int8_t } void - ft_save_name(const char *map_path, t_map *mlist, t_cub *clist) + ft_save_name(const char *map_path, t_cub *clist) { - ft_memdel((void**)&mlist->filename); - if (!(mlist->filename = + ft_memdel((void**)&clist->mlist.filename); + if (!(clist->mlist.filename = (char*)malloc((ft_strlen(map_path) + 1) * sizeof(char)))) ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, clist); - ft_sprintf(mlist->filename, "%s", map_path); + ft_sprintf(clist->mlist.filename, "%s", map_path); } void @@ -95,7 +95,7 @@ void fd = open(map_path, O_RDONLY); if (fd < 0) ft_error(FT_RET_NO_MAP, FT_ERR_NO_MAP, clist); - ft_save_name(map_path, &clist->mlist, clist); + ft_save_name(map_path, clist); ret = 1; while (ret != 12 && ret >= 0) ret = ft_parse_it(fd, clist); diff --git a/src/ft_treat_args.c b/src/ft_treat_args.c index b588b46..accf3aa 100644 --- a/src/ft_treat_args.c +++ b/src/ft_treat_args.c @@ -37,8 +37,13 @@ uint8_t return (ft_exit(FT_RET_FAILED_MLX, clist)); ft_draw_scene(clist); if (clist->mlist.ismusic) - ft_music_fork(cl); + { /* create music fork() here */ + clist->isoldmus = 1; + clist->mpid = fork(); + if (clist->mpid == 0) + ft_music_fork(clist->mlist.music_cmd); + } ft_hooks_and_loops(&clist->wlist, clist); } else if (argc == 3 && !ft_strncmp("--save", argv[2], 7)) diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c index 4d1ca12..0d126c1 100644 --- a/src/ft_warp_level.c +++ b/src/ft_warp_level.c @@ -20,6 +20,7 @@ static void ft_del_map(t_map *ml) { + ft_memdel((void**)&ml->filename); ft_memdel((void**)&ml->no_tex_path); ft_memdel((void**)&ml->so_tex_path); ft_memdel((void**)&ml->ea_tex_path); |