valgrind suppression file for readline()

+ ./.valgrindrc
+ basic free_exit()
+ U_DEFAULT_* macro in _user_macro.h
This commit is contained in:
LuckyLaszlo
2021-10-11 01:58:57 +02:00
parent c0068a5ec7
commit a701488b6a
8 changed files with 45 additions and 14 deletions

4
.valgrindrc Normal file
View File

@@ -0,0 +1,4 @@
--suppressions=./valgrind_readline.supp
--leak-check=full
--show-reachable=yes
--track-fds=yes

View File

@@ -21,7 +21,7 @@ LIBS = -L $(LIBFT_D) -lft \
LIBFT_D = ./libft
LIBFT = $(LIBFT_D)/libft.a
SRCS = main.c init.c generic.c \
SRCS = main.c init.c free.c generic.c \
env.c exit.c
DIR_OBJS = builds

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/08 02:59:58 by lperrey #+# #+# */
/* Updated: 2021/10/10 08:55:48 by lperrey ### ########.fr */
/* Updated: 2021/10/10 23:55:14 by lperrey ### ########.fr */
/* */
/* ************************************************************************** */
@@ -20,6 +20,9 @@ int init(t_all *c, char *envp[]);
int builtin_env(int argc, char *argv[], t_all *c);
int builtin_exit(int argc, char *argv[], t_all *c);
// Free
int free_exit(t_all *c, int exit_status);
// Generic
char *ft_strjoinfree(char *s1, char *s2);
char *ft_strjoinfree_s1(char *s1, const char *s2);

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/10 03:36:37 by lperrey #+# #+# */
/* Updated: 2021/10/10 04:55:46 by lperrey ### ########.fr */
/* Updated: 2021/10/10 20:58:28 by lperrey ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,6 +15,8 @@
# include "minishell_macro.h"
# define USER_PROMPT PROMPT_EURO
# define U_PROMPT_END PROMPT_EURO
# define U_DEFAULT_USER "NoUser"
# define U_DEFAULT_NAME "NoName"
#endif

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/10 05:01:22 by lperrey #+# #+# */
/* Updated: 2021/10/10 08:50:37 by lperrey ### ########.fr */
/* Updated: 2021/10/11 01:50:53 by lperrey ### ########.fr */
/* */
/* ************************************************************************** */
@@ -38,9 +38,5 @@ int builtin_exit(int argc, char *argv[], t_all *c) // WIP
}
status = ft_atoi(argv[1]);
}
// TODO : remplacer exit(status) par
(void)c;
exit(status);
return (0);
// return (free_exit(&c, status));
return (free_exit(c, status));
}

20
srcs/free.c Normal file
View File

@@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* free.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/10 23:53:17 by lperrey #+# #+# */
/* Updated: 2021/10/10 23:59:25 by lperrey ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int free_exit(t_all *c, int exit_status)
{
free(c->prompt_base);
free(c->prompt);
exit(exit_status);
}

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/08 09:22:12 by lperrey #+# #+# */
/* Updated: 2021/10/10 08:54:17 by lperrey ### ########.fr */
/* Updated: 2021/10/10 21:56:33 by lperrey ### ########.fr */
/* */
/* ************************************************************************** */
@@ -37,12 +37,12 @@ static char *init_prompt_base(void)
if (!tmp)
tmp = getenv("LOGNAME");
if (!tmp)
tmp = "NoUser";
tmp = U_DEFAULT_USER;
prompt_base = ft_strjoin(TERM_LIGHT_GREEN, tmp);
prompt_base = ft_strjoinfree_s1(prompt_base, "@");
tmp = getenv("NAME");
if (!tmp)
tmp = "NoName";
tmp = U_DEFAULT_NAME;
prompt_base = ft_strjoinfree_s1(prompt_base, tmp);
prompt_base = ft_strjoinfree_s1(prompt_base, TERM_RESET":"TERM_LIGHT_BLUE);
return (prompt_base);
@@ -53,6 +53,6 @@ static char *init_prompt(char *prompt_base)
char *prompt;
prompt = ft_strjoinfree_s2(prompt_base, getcwd(NULL, 0));
prompt = ft_strjoinfree_s1(prompt, TERM_RESET USER_PROMPT);
prompt = ft_strjoinfree_s1(prompt, TERM_RESET U_PROMPT_END);
return (prompt);
}

6
valgrind_readline.supp Normal file
View File

@@ -0,0 +1,6 @@
{
<readline>
Memcheck:Leak
...
fun:readline
}