fixes + valgrind

This commit is contained in:
gazhonsepaskwa
2025-02-11 10:49:27 +01:00
parent 484ec39641
commit 0c76cc2422
5 changed files with 49 additions and 22 deletions

1
run_vg.sh Executable file
View File

@@ -0,0 +1 @@
make && valgrind --leak-check=full --track-origins=yes --show-leak-kinds=all --trace-children=yes --suppressions=valgrind.supp -s ./minishell

View File

@@ -81,6 +81,7 @@ int main(int ac, char **av, char **envp)
while (!msh->input[0] || is_only_space(msh->input) || g_sig == SIGINT) while (!msh->input[0] || is_only_space(msh->input) || g_sig == SIGINT)
{ {
g_sig = 0; g_sig = 0;
free(msh->input);
msh->input = powerline(msh); msh->input = powerline(msh);
if (!msh->input) if (!msh->input)
break; break;

View File

@@ -162,9 +162,9 @@ t_node *tokenize(char *str)
stick_quote_node(head, 39); stick_quote_node(head, 39);
stick_quote_node(head, '"'); stick_quote_node(head, '"');
debug_token_list(head, "stick quote node"); debug_token_list(head, "stick quote node");
if (!trim_nodes(head)) // if (!trim_nodes(head))
return (NULL); // return (NULL);
debug_token_list(head, "trim_nodes"); // debug_token_list(head, "trim_nodes");
set_token(head); set_token(head);
del_void_nodes(&head); del_void_nodes(&head);
debug_token_list(head, "tokenizer"); debug_token_list(head, "tokenizer");

View File

@@ -12,39 +12,52 @@
#include "../includes/minishell.h" #include "../includes/minishell.h"
static void handle_input(char *in, char *li, char *pr, t_msh *msh) static void handle_input(char *in, t_msh *msh)
{ {
if (ft_strlen(in) > 0 && !is_only_space(in)) if (ft_strlen(in) > 0 && !is_only_space(in))
{ {
add_history(in); add_history(in);
ft_fprintf(msh->hist, "%s\n", in); ft_fprintf(msh->hist, "%s\n", in);
} }
free(pr); }
free(li);
char *get_pwd()
{
char *pwd;
char *pwd_base;
char *cpy;
char *out;
pwd = getcwd(NULL, 0);
pwd_base = pwd;
cpy = pwd;
if (ft_strncmp(pwd, "/home", 5) == 0)
{
pwd += 6;
while (*pwd && (*pwd) != '/')
pwd++;
out = ft_strjoin("~", pwd);
}
else
{
out = ft_strdup(cpy);
}
free(pwd_base);
return (out);
} }
char *powerline(t_msh *msh) char *powerline(t_msh *msh)
{ {
char *pwd; char *pwd;
char *tilt;
char *input; char *input;
char *prompt; char *prompt;
char *line;
pwd = getcwd(NULL, 0); pwd = get_pwd();
tilt = " "; prompt = ft_sprintf("\n%s  MMOAT %s%s %s%s %s%s%s ",
if (ft_strncmp(pwd, "/home/", 6) == 0) POW1, POW2, POW3, POW4, pwd, RESET, POW5, RESET);
{
pwd += 6;
while (*pwd && (*pwd) != '/')
pwd ++;
tilt = " ~";
}
line = ft_sprintf("%s----------------------------------------------\
----------------------------------%s", POW5, RESET);
prompt = ft_sprintf("%s\n%s  MMOAT %s%s%s%s%s %s%s%s ",
line, POW1, POW2, POW3, POW4, tilt, pwd, RESET, POW5, RESET);
input = readline(prompt); input = readline(prompt);
handle_input(input, line, prompt, msh); handle_input(input, msh);
free(prompt);
free(pwd);
return (input); return (input);
} }

12
valgrind.supp Normal file
View File

@@ -0,0 +1,12 @@
{
readline_leak
Memcheck:Leak
...
fun:readline
}
{
readline_leak
Memcheck:Leak
...
fun:add_history
}