From: Christopher Uhlig Date: Sat, 25 Jan 2025 12:01:10 +0000 (+0100) Subject: fixed leaks in tokenizer and collectargs also fixed seg for < > and improved value... X-Git-Url: https://git.dkaiser.de/?a=commitdiff_plain;h=87b90103930d83d74baa998866b0995cb8887d51;p=42%2Fminishell.git fixed leaks in tokenizer and collectargs also fixed seg for < > and improved value add by $ use --- diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json deleted file mode 100644 index 94b2ae4..0000000 --- a/.vscode/c_cpp_properties.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "configurations": [ - { - "name": "macos-clang-x64", - "includePath": [ - "${workspaceFolder}/**" - ], - "compilerPath": "/usr/bin/clang", - "cStandard": "${default}", - "cppStandard": "${default}", - "intelliSenseMode": "macos-clang-x64", - "compilerArgs": [ - "" - ] - } - ], - "version": 4 - } \ No newline at end of file diff --git a/.vscode/launch copy.json b/.vscode/launch copy.json deleted file mode 100644 index 6dcd55f..0000000 --- a/.vscode/launch copy.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "name": "C/C++ Runner: Debug Session", - "type": "lldb", - "request": "launch", - "args": [], - "cwd": "/Users/chuhlig/Documents/", - "program": "/Users/chuhlig/Documents/minishell" - } - ] - } \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 6dcd55f..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "name": "C/C++ Runner: Debug Session", - "type": "lldb", - "request": "launch", - "args": [], - "cwd": "/Users/chuhlig/Documents/", - "program": "/Users/chuhlig/Documents/minishell" - } - ] - } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 91f5074..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,65 +0,0 @@ -{ - "C_Cpp_Runner.cCompilerPath": "clang", - "C_Cpp_Runner.cppCompilerPath": "clang++", - "C_Cpp_Runner.debuggerPath": "lldb", - "C_Cpp_Runner.cStandard": "", - "C_Cpp_Runner.cppStandard": "", - "C_Cpp_Runner.msvcBatchPath": "", - "C_Cpp_Runner.useMsvc": false, - "C_Cpp_Runner.warnings": [ - "-Wall", - "-Wextra", - "-Wpedantic", - "-Wshadow", - "-Wformat=2", - "-Wcast-align", - "-Wconversion", - "-Wsign-conversion", - "-Wnull-dereference" - ], - "C_Cpp_Runner.msvcWarnings": [ - "/W4", - "/permissive-", - "/w14242", - "/w14287", - "/w14296", - "/w14311", - "/w14826", - "/w44062", - "/w44242", - "/w14905", - "/w14906", - "/w14263", - "/w44265", - "/w14928" - ], - "C_Cpp_Runner.enableWarnings": true, - "C_Cpp_Runner.warningsAsError": false, - "C_Cpp_Runner.compilerArgs": [], - "C_Cpp_Runner.linkerArgs": [], - "C_Cpp_Runner.includePaths": [], - "C_Cpp_Runner.includeSearch": [ - "*", - "**/*" - ], - "C_Cpp_Runner.excludeSearch": [ - "**/build", - "**/build/**", - "**/.*", - "**/.*/**", - "**/.vscode", - "**/.vscode/**" - ], - "C_Cpp_Runner.useAddressSanitizer": false, - "C_Cpp_Runner.useUndefinedSanitizer": false, - "C_Cpp_Runner.useLeakSanitizer": false, - "C_Cpp_Runner.showCompilationTime": false, - "C_Cpp_Runner.useLinkTimeOptimization": false, - "C_Cpp_Runner.msvcSecureNoWarnings": false, - "files.associations": { - "minishell.h": "c", - "debug_tools.h": "c", - "token.h": "c", - "ios": "c" - } - } \ No newline at end of file diff --git a/.vscode/tasks copy.json b/.vscode/tasks copy.json deleted file mode 100644 index 4ede37a..0000000 --- a/.vscode/tasks copy.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "tasks": [ - { - "type": "cppbuild", - "label": "C/C++: clang build active file", - "command": "/usr/bin/clang", - "args": [ - "-fcolor-diagnostics", - "-fansi-escape-codes", - "-g", - "${file}", - "-o", - "${fileDirname}/${fileBasenameNoExtension}" - ], - "options": { - "cwd": "${fileDirname}" - }, - "problemMatcher": [ - "$gcc" - ], - "group": { - "kind": "build", - "isDefault": true - }, - "detail": "Task generated by Debugger." - } - ], - "version": "2.0.0" -} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index 4ede37a..0000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "tasks": [ - { - "type": "cppbuild", - "label": "C/C++: clang build active file", - "command": "/usr/bin/clang", - "args": [ - "-fcolor-diagnostics", - "-fansi-escape-codes", - "-g", - "${file}", - "-o", - "${fileDirname}/${fileBasenameNoExtension}" - ], - "options": { - "cwd": "${fileDirname}" - }, - "problemMatcher": [ - "$gcc" - ], - "group": { - "kind": "build", - "isDefault": true - }, - "detail": "Task generated by Debugger." - } - ], - "version": "2.0.0" -} \ No newline at end of file diff --git a/include/minishell.h b/include/minishell.h index 06abb04..97e22cb 100644 --- a/include/minishell.h +++ b/include/minishell.h @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/22 17:14:49 by dkaiser #+# #+# */ -/* Updated: 2025/01/21 20:20:09 by chuhlig ### ########.fr */ +/* Updated: 2025/01/23 23:17:00 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,7 +34,7 @@ void repl(const char *prompt, t_env **env, int *promptflag); t_node *parse(t_token *tokens, t_env **env); t_node *parse_cmd(t_token *tokens, t_env **env); -t_redirection *collect_redirs(t_token **tokens, t_env *env, t_list **cf); +t_redirection *collect_redirs(t_token **tokens, t_env *env, t_list **create_files); void print_ast(t_node *ast); diff --git a/include/token.h b/include/token.h index 67d5737..fb9633d 100644 --- a/include/token.h +++ b/include/token.h @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/27 13:27:18 by dkaiser #+# #+# */ -/* Updated: 2025/01/22 17:27:48 by dkaiser ### ########.fr */ +/* Updated: 2025/01/25 11:42:01 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -50,6 +50,7 @@ void tokenizer(char *s, t_token **token_list, char quote_check); void print_token(t_token *token); -void free_token2(t_token *token); -void free_token_and_connect2(t_token *token); +void free_token2(t_token *token); +void free_token_and_connect2(t_token *token); + #endif diff --git a/lib/libft/ft_strjoin.c b/lib/libft/ft_strjoin.c index 5c0bf41..2cf68ea 100644 --- a/lib/libft/ft_strjoin.c +++ b/lib/libft/ft_strjoin.c @@ -6,41 +6,41 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/07 10:15:33 by dkaiser #+# #+# */ -/* Updated: 2025/01/22 00:27:04 by chuhlig ### ########.fr */ +/* Updated: 2025/01/25 12:55:14 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -// static int copy_str(char *dst, const char *src) -// { -// int i; - -// i = 0; -// while (src[i]) -// { -// dst[i] = src[i]; -// i++; -// } -// return (i); -// } +static int copy_str(char *dst, const char *src) +{ + int i; + + i = 0; + while (src[i]) + { + dst[i] = src[i]; + i++; + } + return (i); +} -char *ft_strjoin(const char *s1, const char *s2) +char *ft_strjoin(char const *s1, char const *s2) { - char *joined_str; - size_t len1; - size_t len2; - - if (!s1 || !s2) - return (NULL); - len1 = strlen(s1); - len2 = strlen(s2); - joined_str = malloc(len1 + len2 + 1); - if (!joined_str) - return (NULL); - strcpy(joined_str, s1); - strcat(joined_str, s2); - return (joined_str); + int len; + char *result; + + len = ft_strlen(s1) + ft_strlen(s2); + result = malloc(len + 1); + if (result) + { + result[len] = '\0'; + len = copy_str(result, s1); + len = copy_str(result + len, s2); + return (result); + } + else + return (0); } /* #include */ diff --git a/src/builtins_part_three.c b/src/builtins_part_three.c index 3b9b100..e7d74a6 100644 --- a/src/builtins_part_three.c +++ b/src/builtins_part_three.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/01/18 18:29:24 by chuhlig #+# #+# */ -/* Updated: 2025/01/21 16:15:19 by chuhlig ### ########.fr */ +/* Updated: 2025/01/24 17:42:49 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/collect_redirs.c b/src/collect_redirs.c index 8f5dadc..860d9bc 100644 --- a/src/collect_redirs.c +++ b/src/collect_redirs.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/02 13:49:31 by dkaiser #+# #+# */ -/* Updated: 2025/01/23 18:22:04 by chuhlig ### ########.fr */ +/* Updated: 2025/01/25 11:40:52 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,7 @@ static int set_heredoc_data(t_token *cur, t_redirection *result, t_env *env); t_redirection *collect_redirs(t_token **tokens, t_env *env, - t_list **create_files)// tokes is possition after pipe or first token + t_list **create_files) { t_redirection *result; t_token *cur; @@ -31,15 +31,14 @@ t_redirection *collect_redirs(t_token **tokens, t_env *env, result = malloc(sizeof(t_redirection) * 2); if (result == NULL) return (free_tokens(*tokens), NULL); - free(set_redir(&result[0], 0, NULL, env));// no token use - free(set_redir(&result[1], 0, NULL, env));// no token use + free(set_redir(&result[0], 0, NULL, env)); + free(set_redir(&result[1], 0, NULL, env)); data.create_files = create_files; data.env = env; while (cur != NULL) { - if (cur->type == REDIR_TOKEN && cur->next->type == STRING_TOKEN)//could this be a problem with recursion? - collect_and_check_redir(result, &cur, &data, tokens);// cur=token is just in there to free and connect dont know if its ok - //return or better said does + if (cur->type == REDIR_TOKEN && cur->next->type == STRING_TOKEN) + collect_and_check_redir(result, &cur, &data, tokens); else if (cur->type == REDIR_TOKEN) return (free(result), NULL); else @@ -57,21 +56,20 @@ static void collect_and_check_redir(t_redirection *result, t_token **cur, str = ft_strdup((*cur)->next->content.string); if ((*cur)->content.redir_type == INPUT_LIMITER) { - if (!set_heredoc_data(*cur, result, data->env))// set here doc data with token head or first token after pipe + if (!set_heredoc_data(*cur, result, data->env)) return ; } else if ((*cur)->content.redir_type == INPUT_FILE) q4fc(data->create_files, set_redir(&result[0], INPUT_FILE, - format_string(str, data->env, 0), data->env));//here toke list should be not messed up + format_string(str, data->env, 0), data->env)); else if ((*cur)->content.redir_type == OUTPUT_OVERRIDE) q4fc(data->create_files, set_redir(&result[1], OUTPUT_OVERRIDE, format_string(str, data->env, 0), data->env)); - else if ((*cur)->content.redir_type == OUTPUT_APPEND) + else if ((*cur)->content.redir_type == OUTPUT_APPEND) q4fc(data->create_files, set_redir(&result[1], OUTPUT_APPEND, format_string(str, data->env, 0), data->env)); - i_love_the_norme(cur, tokens);// takes adress of token head or pos after pipe and the token specifer -}// i love the norm simple does free token and connect -//later more detailes + i_love_the_norme(cur, tokens); +} static t_redirection *set_redir(t_redirection *redir, int type, char *spec, t_env *env) @@ -79,8 +77,6 @@ static t_redirection *set_redir(t_redirection *redir, int type, char *spec, t_redirection *result; redir->type = type; - // if (redir->specifier != NULL) - // free(redir->specifier); if (spec != NULL) redir->specifier = format_string(spec, env, ft_atoi("0")); else diff --git a/src/debug_tools.c b/src/debug_tools.c index 2c8ee7e..3c38cd6 100644 --- a/src/debug_tools.c +++ b/src/debug_tools.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/24 15:34:14 by dkaiser #+# #+# */ -/* Updated: 2025/01/23 15:21:11 by chuhlig ### ########.fr */ +/* Updated: 2025/01/25 11:39:59 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,21 +35,3 @@ void panic(char *msg) ft_putendl_fd("\e[0m", 1); } } - - - -void print_token_list(t_token *token_list) { - t_token *current = token_list; - while (current != NULL) { - if (current->type == STRING_TOKEN) { - printf("STRING_TOKEN: %s\n", current->content.string); - } else if (current->type == REDIR_TOKEN) { - printf("REDIR_TOKEN: %d\n", current->content.redir_type); - } else if (current->type == PIPE_TOKEN) { - printf("PIPE_TOKEN\n"); - } else if (current->type == NEWLINE_TOKEN) { - printf("NEWLINE_TOKEN\n"); - } - current = current->next; - } -} diff --git a/src/execute_cmd.c b/src/execute_cmd.c index 811c92c..9f00522 100644 --- a/src/execute_cmd.c +++ b/src/execute_cmd.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/17 19:21:35 by chuhlig #+# #+# */ -/* Updated: 2025/01/22 16:53:04 by dkaiser ### ########.fr */ +/* Updated: 2025/01/25 11:41:42 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,14 +17,6 @@ static void establish_pipeline(int original_stdin, int original_stdout); static int exec_cmd(t_cmd *cmd, t_env **env, int original_std[2], int result); -int invalid_input(char *cmd) -{ - ft_putstr_fd("minishell: ", STDERR_FILENO); - ft_putstr_fd(cmd, STDERR_FILENO); - ft_putstr_fd(": command not found\n", STDERR_FILENO); - return (127); -} - int is_builtin(char *cmd) { return ((ft_strcmp(cmd, "export") == 0) || (ft_strcmp(cmd, "unset") == 0) @@ -104,7 +96,6 @@ static int exec_cmd(t_cmd *cmd, t_env **env, int original_std[2], int result) cmd_path = get_cmd_path(cmd->args[i], *env, &result); if (cmd_path != NULL) execve(cmd_path, &(cmd->args[i]), env_to_strlst(*env)); - // free(cmd_path); exit(result); } waitpid(pid, &status, 0); diff --git a/src/format_string.c b/src/format_string.c index 06e5210..e649fdb 100644 --- a/src/format_string.c +++ b/src/format_string.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/17 19:30:11 by chuhlig #+# #+# */ -/* Updated: 2025/01/23 14:34:35 by chuhlig ### ########.fr */ +/* Updated: 2025/01/25 11:57:27 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -49,11 +49,8 @@ static void append_slice(char **dst, char *src, int start, int end) i++; } result[len + i] = '\0'; - // if (*dst != NULL) - // free(*dst); + free(*dst); *dst = result; - // free(src); - // src = *dst; } static void append_var(char **dst, char *src, int *pos, t_env *env) @@ -73,6 +70,8 @@ static void append_var(char **dst, char *src, int *pos, t_env *env) value = env_get(env, var); if (value) { + while (*value == ' ') + value++; result = ft_strjoin(*dst, value); free(*dst); *dst = result; @@ -81,7 +80,8 @@ static void append_var(char **dst, char *src, int *pos, t_env *env) free(var); } -static void handle_dollar_sign(char **result, char *str, int *pos, t_env *env) +static void handle_dollar_sign(char **result, char *str, int *pos, + t_env *env) { if (str[*pos + 1] == '?') { diff --git a/src/free_node.c b/src/free_node.c index 733fe1c..e62d6cb 100644 --- a/src/free_node.c +++ b/src/free_node.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/27 11:41:46 by dkaiser #+# #+# */ -/* Updated: 2025/01/22 16:00:36 by chuhlig ### ########.fr */ +/* Updated: 2025/01/25 11:39:01 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,96 +16,49 @@ static void free_pipe_node(t_node *node); static void free_cmd_node(t_node *node); static void free_file(void *arg); -// void free_node(t_node *node) -// { -// if (node->type == PIPE_NODE) -// free_pipe_node(node); -// else if (node->type == CMD_NODE) -// free_cmd_node(node); -// else if (node->type == STRING_NODE) -// free(node->content.string); -// else -// panic(UNREACHABLE); -// free(node); -// } - -// static void free_pipe_node(t_node *node) -// { -// free_node(node->content.pipe.left); -// free_node(node->content.pipe.right); -// } - -// static void free_cmd_node(t_node *node) -// { -// int i; - -// i = 0; -// while (node->content.cmd.args != NULL && node->content.cmd.args[i] != NULL) -// { -// free(node->content.cmd.args[i]); -// i++; -// } -// free(node->content.cmd.args); -// if (node->content.cmd.redirs[0].type != 0 -// && node->content.cmd.redirs[0].specifier != NULL) -// free(node->content.cmd.redirs[0].specifier); -// if (node->content.cmd.redirs[1].type != 0 -// && node->content.cmd.redirs[0].specifier != NULL) -// free(node->content.cmd.redirs[1].specifier); -// if (node->content.cmd.create_files != NULL) -// ft_lstclear(&node->content.cmd.create_files, free_file); -// } - -// static void free_file(void *arg) -// { -// t_redirection *file; - -// file = (t_redirection *)arg; -// free(file->specifier); -// free(file); -// } - -void free_node(t_node *node) +void free_node(t_node *node) { - if (node->type == PIPE_NODE) - free_pipe_node(node); - else if (node->type == CMD_NODE) - free_cmd_node(node); - else if (node->type == STRING_NODE) - free(node->content.string); - free(node); + if (node->type == PIPE_NODE) + free_pipe_node(node); + else if (node->type == CMD_NODE) + free_cmd_node(node); + else if (node->type == STRING_NODE) + free(node->content.string); + free(node); } -static void free_pipe_node(t_node *node) +static void free_pipe_node(t_node *node) { - free_node(node->content.pipe.left); - free_node(node->content.pipe.right); + free_node(node->content.pipe.left); + free_node(node->content.pipe.right); } -static void free_cmd_node(t_node *node) +static void free_cmd_node(t_node *node) { - int i; + int i; - i = 0; - while (node->content.cmd.args != NULL && node->content.cmd.args[i] != NULL) - { - free(node->content.cmd.args[i]); - i++; - } - free(node->content.cmd.args); - if (node->content.cmd.redirs[0].type != 0 && node->content.cmd.redirs[0].specifier != NULL) - free(node->content.cmd.redirs[0].specifier); - if (node->content.cmd.redirs[1].type != 0 && node->content.cmd.redirs[1].specifier != NULL) - free(node->content.cmd.redirs[1].specifier); - if (node->content.cmd.create_files != NULL) - ft_lstclear(&node->content.cmd.create_files, free_file); + i = 0; + while (node->content.cmd.args != NULL && node->content.cmd.args[i] != NULL) + { + free(node->content.cmd.args[i]); + i++; + } + free(node->content.cmd.args); + if (node->content.cmd.redirs[0].type != 0 + && node->content.cmd.redirs[0].specifier != NULL) + free(node->content.cmd.redirs[0].specifier); + if (node->content.cmd.redirs[1].type != 0 + && node->content.cmd.redirs[1].specifier != NULL) + free(node->content.cmd.redirs[1].specifier); + if (node->content.cmd.create_files != NULL) + ft_lstclear(&node->content.cmd.create_files, free_file); } -static void free_file(void *arg) +static void free_file(void *arg) { - t_redirection *file; + t_redirection *file; - file = (t_redirection *)arg; - free(file->specifier); - free(file); -} \ No newline at end of file + file = (t_redirection *)arg; + free(file->specifier); + free(file); +} diff --git a/src/free_token.c b/src/free_token.c index 2292eb0..a63e750 100644 --- a/src/free_token.c +++ b/src/free_token.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/27 14:38:57 by dkaiser #+# #+# */ -/* Updated: 2025/01/22 17:28:31 by dkaiser ### ########.fr */ +/* Updated: 2025/01/25 11:36:59 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,12 +19,7 @@ void free_token(t_token *token) token->previous->next = NULL; if (token->next != NULL) token->next->previous = NULL; - // if (token->previous == NULL && token->next == NULL) - // { - // if (token->type == STRING_TOKEN && token->content.string != NULL) - // free(token->content.string); // Ensure content is freed - // } - free(token);//maybe free token + free(token); token = NULL; } @@ -34,13 +29,12 @@ void free_token2(t_token *token) token->previous->next = NULL; if (token->next != NULL) token->next->previous = NULL; - if (token->type == STRING_TOKEN && token->content.string != NULL) - free(token->content.string); // Ensure content is freed - free(token);//maybe free token + if (token->type == STRING_TOKEN && token->content.string != NULL) + free(token->content.string); + free(token); token = NULL; } - void free_token_and_connect(t_token *token) { if (token->previous != NULL) @@ -58,7 +52,7 @@ void free_token_and_connect2(t_token *token) if (token->next != NULL) token->next->previous = token->previous; if (token->type == STRING_TOKEN && token->content.string != NULL) - free(token->content.string); // Ensure content is freed + free(token->content.string); free(token); token = NULL; } @@ -72,14 +66,3 @@ void free_tokens(t_token *tokens) } free_token2(tokens); } -// void free_tokens(t_token *tokens) -// { -// t_token *tmp; - -// while (tokens) -// { -// tmp = tokens; -// tokens = tokens->next; -// free_token(tmp); // Ensure each token is freed -// } -// } diff --git a/src/get_cmd_path.c b/src/get_cmd_path.c index f882734..8075a5f 100644 --- a/src/get_cmd_path.c +++ b/src/get_cmd_path.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/17 19:19:59 by chuhlig #+# #+# */ -/* Updated: 2025/01/22 16:59:48 by dkaiser ### ########.fr */ +/* Updated: 2025/01/25 11:36:28 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -66,8 +66,7 @@ static char *find_in_path(char *cmd, t_env *env, int *return_code) char *cur_path; char *cmd_path; char **path; - char **path_start; - + char **path_start; path = get_split_path(env); path_start = path; @@ -94,30 +93,6 @@ static char *find_in_path(char *cmd, t_env *env, int *return_code) return (NULL); } -// static char *get_simple_cmd_path(char *cmd, int *return_code) -// { -// char *result; - -// result = ft_strdup(cmd); -// if (!result) -// return (NULL); -// if (access(result, F_OK) == -1) -// { -// free(result); -// return (error(ENOENT, cmd, 127, return_code)); -// } -// if (access(result, X_OK) == -1) -// { -// free(result); -// return (error(EACCES, cmd, 126, return_code)); -// } -// if (is_directory(cmd)) -// { -// free(result); -// return (error(EISDIR, cmd, 126, return_code)); -// } -// return (result); -// } static char *get_simple_cmd_path(char *cmd, int *return_code) { char *result; diff --git a/src/main.c b/src/main.c index e863f3a..6fbe58c 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/22 17:14:03 by dkaiser #+# #+# */ -/* Updated: 2025/01/22 01:49:12 by chuhlig ### ########.fr */ +/* Updated: 2025/01/25 10:25:42 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/new_token.c b/src/new_token.c index 6f49681..c9bd28c 100644 --- a/src/new_token.c +++ b/src/new_token.c @@ -6,11 +6,12 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/27 14:29:44 by dkaiser #+# #+# */ -/* Updated: 2025/01/22 00:41:47 by chuhlig ### ########.fr */ +/* Updated: 2025/01/24 18:46:05 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ #include "token.h" +#include "libft.h" t_token *new_token(int type, t_token *previous, t_token *next) { @@ -39,7 +40,7 @@ t_token *new_str_token(char *str, t_token *previous, t_token *next) free(str); return (NULL); } - token->content.string = str; + token->content.string = ft_strdup(str); return (token); } diff --git a/src/parse_cmd.c b/src/parse_cmd.c index a978c99..5f9e36d 100644 --- a/src/parse_cmd.c +++ b/src/parse_cmd.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/08 15:06:25 by dkaiser #+# #+# */ -/* Updated: 2025/01/23 18:04:50 by chuhlig ### ########.fr */ +/* Updated: 2025/01/25 11:36:09 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,16 +21,10 @@ t_node *parse_cmd(t_token *tokens, t_env **env) t_list *create_files; create_files = NULL; - printf("parse_cmd\n"); - print_token_list(tokens); - redirs = collect_redirs(&tokens, *env, &create_files);// takes pos next to pipe or first token - printf("parse_cmdafter collect redir\n"); - print_token_list(tokens);// still existing tokenlist + redirs = collect_redirs(&tokens, *env, &create_files); if (redirs == NULL) return (NULL); args = collect_args(&tokens, env); - printf("parse_cmdafter collect args\n"); - // print_token_list(tokens);//here it gone if (args == NULL) { free(redirs); @@ -39,64 +33,33 @@ t_node *parse_cmd(t_token *tokens, t_env **env) return (new_cmd_node(args, redirs, create_files)); } -// static char **collect_args(t_token **tokens, t_env **env) -// { -// t_token *cur; -// char **result; -// int i; -// t_token *next; - -// cur = *tokens; -// i = 0; -// while (cur != NULL && ++i) -// cur = cur->next; -// result = malloc(sizeof(char *) * (i + 1)); -// if (result == NULL) -// return (free_tokens(*tokens), NULL); -// cur = *tokens; -// i = 0; -// while (cur != NULL && cur->type == STRING_TOKEN) -// { -// next = cur->next; -// if (cur->previous) -// free_token(cur->previous); -// result[i] = format_string(cur->content.string, *env, ft_atoi("0")); -// i++; -// if (cur->next == NULL) -// free_token(cur); -// cur = next; -// } -// result[i] = NULL; -// return (result); -// } - -static char **collect_args(t_token **tokens, t_env **env) { - t_token *cur; - char **result; - int i; - t_token *next; +static char **collect_args(t_token **tokens, t_env **env) +{ + t_token *cur; + char **result; + int i; + t_token *next; - cur = *tokens; - i = 0; - while (cur != NULL && ++i) - cur = cur->next; - result = malloc(sizeof(char *) * (i + 1)); - if (result == NULL) - return (free_tokens(*tokens), NULL); - cur = *tokens; - i = 0; - while (cur != NULL && cur->type == STRING_TOKEN) { - next = cur->next; - result[i] = format_string(cur->content.string, *env, ft_atoi("0")); - i++; - if (cur->previous) - cur->previous->next = cur->next; - if (cur->next) - cur->next->previous = cur->previous; - free_token(cur); - cur = next; - } - result[i] = NULL; - *tokens = cur; // Update the head of the token list - return (result); -}// need to later the rest of the tokenlist + cur = *tokens; + i = 0; + while (cur != NULL && ++i) + cur = cur->next; + result = malloc(sizeof(char *) * (i + 1)); + if (result == NULL) + return (free_tokens(*tokens), NULL); + cur = *tokens; + i = 0; + while (cur != NULL && cur->type == STRING_TOKEN) + { + next = cur->next; + if (cur->previous) + free_token2(cur->previous); + result[i] = format_string(cur->content.string, *env, ft_atoi("0")); + i++; + if (cur->next == NULL) + free_token2(cur); + cur = next; + } + result[i] = NULL; + return (result); +} diff --git a/src/parser.c b/src/parser.c index 68ab372..8393cda 100644 --- a/src/parser.c +++ b/src/parser.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/29 15:53:29 by dkaiser #+# #+# */ -/* Updated: 2025/01/23 18:00:18 by chuhlig ### ########.fr */ +/* Updated: 2025/01/25 11:38:47 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,28 +21,30 @@ static t_node *parse_statement(t_token *tokens, t_env **env); t_node *parse(t_token *tokens, t_env **env) { - t_node *result;// + t_node *result; - if ((*tokens).type == PIPE_TOKEN) + if ((*tokens).type == PIPE_TOKEN + || ((*tokens).type == REDIR_TOKEN && !(*tokens).next)) + { result = NULL; + free_tokens(tokens); + } else result = parse_statement(tokens, env); if (result == NULL) + { printf("Parsing error.\n"); - // if (tokens != NULL) - // print_token_list(tokens); + free_tokens(tokens); + } return (result); } static t_node *parse_statement(t_token *tokens, t_env **env) { t_token *left_side_tokens; - - print_token_list(tokens);//until her is fine - left_side_tokens = split_at_first(&tokens, PIPE_TOKEN);//by pipe usage parse cmd gets reacls so also check there the token list changes - //leftside toke has the pos of pipe -> next - //or if we have pipe we return token head and also change the *tokens to after pipe - if (left_side_tokens == NULL)// we never return NULL exept token is already null + + left_side_tokens = split_at_first(&tokens, PIPE_TOKEN); + if (left_side_tokens == NULL) { free_tokens(tokens); tokens = NULL; @@ -51,13 +53,12 @@ static t_node *parse_statement(t_token *tokens, t_env **env) else if (tokens != NULL) { return (new_pipe_node(parse_cmd(left_side_tokens, env), - parse_statement(tokens, env)));//here new pipe node + parse_statement(tokens, env))); } else { - print_token_list(left_side_tokens); - return (parse_cmd(left_side_tokens, env));//here return is cmd node - }// here he takt left side token so + return (parse_cmd(left_side_tokens, env)); + } } t_token *split_at_first(t_token **tokens, int type) @@ -65,24 +66,21 @@ t_token *split_at_first(t_token **tokens, int type) t_token *split; t_token *result; - split = find_token_by_type(*tokens, type);//split has the pos of where pipe appears// if no pipe in tokenlist 1st if case + split = find_token_by_type(*tokens, type); if (split == NULL) { result = *tokens; - *tokens = NULL;//we are change to pointing token to NULL + *tokens = NULL; return (result); } result = *tokens; - *tokens = split->next;// is this part enought reconnetion + *tokens = split->next; if (result == split) result = NULL; - free_token2(split);//why free here? bv would free pipe node but what is with the connection of the tokenlist does this mess up the connection? + free_token2(split); split = NULL; - return (result);// at this return return is at tokenlist pos of split next and result is the tokenlist before split + return (result); } -//free token seems not right here even -// or at least no the right funtion here -// static t_token *find_token_by_type(t_token *tokens, int type) { diff --git a/src/praise_the_norme.c b/src/praise_the_norme.c index 5639b7d..7b72172 100644 --- a/src/praise_the_norme.c +++ b/src/praise_the_norme.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/01/20 18:35:41 by dkaiser #+# #+# */ -/* Updated: 2025/01/23 18:31:49 by chuhlig ### ########.fr */ +/* Updated: 2025/01/25 11:34:26 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,19 +16,15 @@ void i_love_the_norme(t_token **cur, t_token **tokens) { t_token *next_token; - next_token = (*cur)->next;//setting next token to the adress of the next token - free_token_and_connect(*cur);// do i neee a double call here - //but technically it would remove the redir token - if (next_token)// if after redir is stuff + next_token = (*cur)->next; + free_token_and_connect2(*cur); + if (next_token) { - if (next_token->previous == NULL)// then if is the first token or token after pipe - *tokens = next_token->next;// how does here come no error - //anyways i twould the redir adress token to the next token + if (next_token->previous == NULL) + *tokens = next_token->next; *cur = next_token->next; free_token_and_connect(next_token); } - else // else makes sense + else *cur = NULL; } - -// takes adress of token head or pos after pipe and the token specifer \ No newline at end of file diff --git a/src/repl.c b/src/repl.c index 3988a42..93874a7 100644 --- a/src/repl.c +++ b/src/repl.c @@ -6,48 +6,17 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/24 16:07:04 by dkaiser #+# #+# */ -/* Updated: 2025/01/23 17:42:33 by chuhlig ### ########.fr */ +/* Updated: 2025/01/25 12:41:48 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ #include "../include/minishell.h" #include "token.h" -t_token *shallow_copy_token(t_token *token) -{ - if (token == NULL) - return (NULL); - - if (token->type == STRING_TOKEN) - return (new_str_token(token->content.string, NULL, NULL)); - else if (token->type == REDIR_TOKEN) - return (new_redir_token(token->content.redir_type, NULL, NULL)); - else - return (new_redir_token(token->type, NULL, NULL)); -} - -t_token *shallow_copy_tokens(t_token *tokens) -{ - t_token *result; - t_token *cur; - - result = shallow_copy_token(tokens); - if (!result) - return (NULL); - cur = result; - while (tokens->next != NULL) - { - tokens = tokens->next; - cur->next = shallow_copy_tokens(tokens); - cur = cur->next; - } - return (result); -} - void free_repl(char *input, t_node *ast) { free(input); - if(ast) + if (ast) free_node(ast); } @@ -56,7 +25,6 @@ void repl(const char *prompt, t_env **env, int *promptflag) char *input; t_token *token_list; t_node *ast; - t_token *tokens_copy; (*promptflag)++; while (1) @@ -70,17 +38,16 @@ void repl(const char *prompt, t_env **env, int *promptflag) break ; } if (input[0] == '\0') + { + free(input); continue ; + } add_history(input); token_list = NULL; tokenizer(input, &token_list, '\0'); - tokens_copy = shallow_copy_tokens(token_list); - free_tokens(tokens_copy); - // print_token_list(token_list); ast = parse(token_list, env); if (ast) set_return_code(eval(ast, env), env); free_repl(input, ast); - print_token_list(tokens_copy); } } diff --git a/src/tokenizer.c b/src/tokenizer.c index 451fa50..90cb521 100644 --- a/src/tokenizer.c +++ b/src/tokenizer.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/28 20:55:50 by chuhlig #+# #+# */ -/* Updated: 2025/01/22 00:49:10 by chuhlig ### ########.fr */ +/* Updated: 2025/01/25 11:30:58 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -60,12 +60,15 @@ void snap_string_token(char *string, int start_of_string, int i, t_token **token_list) { char *line; + char *original; int len; + line = NULL; len = i - start_of_string + 1; if (len > 0) { - line = (char *)malloc(len + 1); + line = (char *)malloc((sizeof(char) * len + 1)); + original = line; if (!line) { exit(EXIT_FAILURE); @@ -79,6 +82,7 @@ void snap_string_token(char *string, int start_of_string, int i, *token_list = new_str_token(line, *token_list, NULL); print_token(*token_list); } + free(original); } } diff --git a/valgrind_out.txt b/valgrind_out.txt deleted file mode 100644 index c005c63..0000000 --- a/valgrind_out.txt +++ /dev/null @@ -1,1040 +0,0 @@ -root@aaf7f63c7efc:/dorker_workspace# valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./minishell -==7626== Memcheck, a memory error detector -==7626== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al. -==7626== Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info -==7626== Command: ./minishell -==7626== -Minishell $ a -==7626== Invalid read of size 8 -==7626== at 0x1097D1: free_tokens (free_token.c:55) -==7626== by 0x10A08A: parse (parser.c:40) -==7626== by 0x109586: repl (repl.c:51) -==7626== by 0x109372: main (main.c:28) -==7626== Address 0x4b01c38 is 24 bytes inside a block of size 32 free'd -==7626== at 0x484317B: free (vg_replace_malloc.c:872) -==7626== by 0x109746: free_token (free_token.c:24) -==7626== by 0x10A395: collect_args (parse_cmd.c:91) -==7626== by 0x10A24F: parse_cmd (parse_cmd.c:27) -==7626== by 0x10A12A: parse_statement (parser.c:62) -==7626== by 0x10A07A: parse (parser.c:39) -==7626== by 0x109586: repl (repl.c:51) -==7626== by 0x109372: main (main.c:28) -==7626== Block was alloc'd at -==7626== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7626== by 0x1095F6: new_token (new_token.c:19) -==7626== by 0x109686: new_str_token (new_token.c:36) -==7626== by 0x109C55: snap_string_token (tokenizer.c:79) -==7626== by 0x10A014: tokenizer (tokenizer.c:130) -==7626== by 0x109573: repl (repl.c:50) -==7626== by 0x109372: main (main.c:28) -==7626== -==7626== Invalid read of size 8 -==7626== at 0x1097DD: free_tokens (free_token.c:56) -==7626== by 0x10A08A: parse (parser.c:40) -==7626== by 0x109586: repl (repl.c:51) -==7626== by 0x109372: main (main.c:28) -==7626== Address 0x4b01c28 is 8 bytes inside a block of size 32 free'd -==7626== at 0x484317B: free (vg_replace_malloc.c:872) -==7626== by 0x109746: free_token (free_token.c:24) -==7626== by 0x10A395: collect_args (parse_cmd.c:91) -==7626== by 0x10A24F: parse_cmd (parse_cmd.c:27) -==7626== by 0x10A12A: parse_statement (parser.c:62) -==7626== by 0x10A07A: parse (parser.c:39) -==7626== by 0x109586: repl (repl.c:51) -==7626== by 0x109372: main (main.c:28) -==7626== Block was alloc'd at -==7626== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7626== by 0x1095F6: new_token (new_token.c:19) -==7626== by 0x109686: new_str_token (new_token.c:36) -==7626== by 0x109C55: snap_string_token (tokenizer.c:79) -==7626== by 0x10A014: tokenizer (tokenizer.c:130) -==7626== by 0x109573: repl (repl.c:50) -==7626== by 0x109372: main (main.c:28) -==7626== -==7626== Invalid free() / delete / delete[] / realloc() -==7626== at 0x484317B: free (vg_replace_malloc.c:872) -==7626== by 0x1097F4: free_tokens (free_token.c:57) -==7626== by 0x10A08A: parse (parser.c:40) -==7626== by 0x109586: repl (repl.c:51) -==7626== by 0x109372: main (main.c:28) -==7626== Address 0x4b01c20 is 0 bytes inside a block of size 32 free'd -==7626== at 0x484317B: free (vg_replace_malloc.c:872) -==7626== by 0x109746: free_token (free_token.c:24) -==7626== by 0x10A395: collect_args (parse_cmd.c:91) -==7626== by 0x10A24F: parse_cmd (parse_cmd.c:27) -==7626== by 0x10A12A: parse_statement (parser.c:62) -==7626== by 0x10A07A: parse (parser.c:39) -==7626== by 0x109586: repl (repl.c:51) -==7626== by 0x109372: main (main.c:28) -==7626== Block was alloc'd at -==7626== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7626== by 0x1095F6: new_token (new_token.c:19) -==7626== by 0x109686: new_str_token (new_token.c:36) -==7626== by 0x109C55: snap_string_token (tokenizer.c:79) -==7626== by 0x10A014: tokenizer (tokenizer.c:130) -==7626== by 0x109573: repl (repl.c:50) -==7626== by 0x109372: main (main.c:28) -==7626== -a: command not found -==7627== -==7627== HEAP SUMMARY: -==7627== in use at exit: 199,597 bytes in 269 blocks -==7627== total heap usage: 450 allocs, 182 frees, 224,561 bytes allocated -==7627== -==7627== 2 bytes in 1 blocks are still reachable in loss record 1 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x10D412: ft_strdup (in /dorker_workspace/minishell) -==7627== by 0x10C82F: set_return_code (builtins_part_three.c:44) -==7627== by 0x109355: main (main.c:27) -==7627== -==7627== 2 bytes in 1 blocks are still reachable in loss record 2 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x10CFE2: ft_itoa (in /dorker_workspace/minishell) -==7627== by 0x10C85F: set_return_code (builtins_part_three.c:48) -==7627== by 0x109355: main (main.c:27) -==7627== -==7627== 2 bytes in 1 blocks are still reachable in loss record 3 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x489124E: _rl_init_locale (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4891321: _rl_init_eightbit (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48700F2: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 2 bytes in 1 blocks are still reachable in loss record 4 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x486EFB9: readline_internal_teardown (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48703DA: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 2 bytes in 1 blocks are still reachable in loss record 5 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x489258C: alloc_history_entry (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48927F9: add_history (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x109553: repl (repl.c:48) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 2 bytes in 1 blocks are still reachable in loss record 6 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x10B868: append_slice (format_string.c:41) -==7627== by 0x10BC33: format_string (format_string.c:124) -==7627== by 0x10A375: collect_args (parse_cmd.c:88) -==7627== by 0x10A24F: parse_cmd (parse_cmd.c:27) -==7627== by 0x10A12A: parse_statement (parser.c:62) -==7627== by 0x10A07A: parse (parser.c:39) -==7627== by 0x109586: repl (repl.c:51) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 5 bytes in 1 blocks are still reachable in loss record 7 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x494C969: strdup (strdup.c:42) -==7627== by 0x4AA4435: _nc_setupterm (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AA4922: tgetent_sp (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x488E45C: _rl_init_terminal_io (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48700D0: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 6 bytes in 1 blocks are still reachable in loss record 8 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48976A6: sh_get_home_dir (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x489832C: tilde_expand_word (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4898560: tilde_expand (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487E26B: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487E4FB: rl_read_init_file (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48700F9: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 7 bytes in 1 blocks are definitely lost in loss record 9 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x10D4F9: ft_strjoin (in /dorker_workspace/minishell) -==7627== by 0x10AFDA: find_in_path (get_cmd_path.c:79) -==7627== by 0x10ADFF: get_cmd_path (get_cmd_path.c:34) -==7627== by 0x10B720: exec_cmd (execute_cmd.c:96) -==7627== by 0x10B622: execute_cmd (execute_cmd.c:66) -==7627== by 0x10AB22: eval_rec (interpreter.c:46) -==7627== by 0x10AB67: eval (interpreter.c:57) -==7627== by 0x1095A4: repl (repl.c:53) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 8 bytes in 1 blocks are still reachable in loss record 10 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899377: xrealloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4881C4E: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48827F5: rl_expand_prompt (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x486ECFE: rl_set_prompt (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4870385: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 12 bytes in 1 blocks are still reachable in loss record 11 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48927D7: add_history (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x109553: repl (repl.c:48) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 13 bytes in 1 blocks are still reachable in loss record 12 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x486ECDA: rl_set_prompt (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4870385: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 13 bytes in 1 blocks are still reachable in loss record 13 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4882183: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48827F5: rl_expand_prompt (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x486ECFE: rl_set_prompt (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4870385: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 13 bytes in 1 blocks are still reachable in loss record 14 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487E422: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48700F9: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 16 bytes in 1 blocks are still reachable in loss record 15 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x48701E7: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 16 bytes in 1 blocks are still reachable in loss record 16 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x10A2DC: collect_args (parse_cmd.c:78) -==7627== by 0x10A24F: parse_cmd (parse_cmd.c:27) -==7627== by 0x10A12A: parse_statement (parser.c:62) -==7627== by 0x10A07A: parse (parser.c:39) -==7627== by 0x109586: repl (repl.c:51) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 20 bytes in 1 blocks are still reachable in loss record 17 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487F143: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487DFD2: rl_parse_and_bind (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487E39C: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48700F9: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 24 bytes in 1 blocks are still reachable in loss record 18 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x10AD28: env_new (env.c:69) -==7627== by 0x10C837: set_return_code (builtins_part_three.c:44) -==7627== by 0x109355: main (main.c:27) -==7627== -==7627== 24 bytes in 1 blocks are still reachable in loss record 19 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4892573: alloc_history_entry (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48927F9: add_history (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x109553: repl (repl.c:48) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 33 bytes in 1 blocks are still reachable in loss record 20 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4AABF1A: _nc_read_termtype (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AACB1A: _nc_read_file_entry (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AACE7C: ??? (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AACFCB: _nc_read_entry2 (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AA4018: ??? (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AA43D5: _nc_setupterm (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AA4922: tgetent_sp (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x488E45C: _rl_init_terminal_io (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48700D0: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== -==7627== 33 bytes in 1 blocks are still reachable in loss record 21 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4A9F2E8: ??? (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AA4404: _nc_setupterm (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AA4922: tgetent_sp (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x488E45C: _rl_init_terminal_io (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48700D0: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 40 bytes in 1 blocks are still reachable in loss record 22 of 67 -==7627== at 0x48455EF: calloc (vg_replace_malloc.c:1328) -==7627== by 0x4AA15CB: _nc_first_db (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AACFA6: _nc_read_entry2 (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AA4018: ??? (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AA43D5: _nc_setupterm (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AA4922: tgetent_sp (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x488E45C: _rl_init_terminal_io (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48700D0: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 44 bytes in 1 blocks are still reachable in loss record 23 of 67 -==7627== at 0x48455EF: calloc (vg_replace_malloc.c:1328) -==7627== by 0x4AAC020: _nc_read_termtype (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AACB1A: _nc_read_file_entry (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AACE7C: ??? (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AACFCB: _nc_read_entry2 (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AA4018: ??? (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AA43D5: _nc_setupterm (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AA4922: tgetent_sp (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x488E45C: _rl_init_terminal_io (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48700D0: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== -==7627== 44 bytes in 1 blocks are still reachable in loss record 24 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4A9F0BE: ??? (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AA4404: _nc_setupterm (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AA4922: tgetent_sp (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x488E45C: _rl_init_terminal_io (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48700D0: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 56 bytes in 1 blocks are still reachable in loss record 25 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x109814: new_node (new_node.c:19) -==7627== by 0x1098B2: new_cmd_node (new_node.c:45) -==7627== by 0x10A284: parse_cmd (parse_cmd.c:33) -==7627== by 0x10A12A: parse_statement (parser.c:62) -==7627== by 0x10A07A: parse (parser.c:39) -==7627== by 0x109586: repl (repl.c:51) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 61 bytes in 6 blocks are indirectly lost in loss record 26 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x10D193: get_next_token (in /dorker_workspace/minishell) -==7627== by 0x10D27E: ft_split (in /dorker_workspace/minishell) -==7627== by 0x10C32A: get_split_path (env_tools.c:20) -==7627== by 0x10AF78: find_in_path (get_cmd_path.c:70) -==7627== by 0x10ADFF: get_cmd_path (get_cmd_path.c:34) -==7627== by 0x10B720: exec_cmd (execute_cmd.c:96) -==7627== by 0x10B622: execute_cmd (execute_cmd.c:66) -==7627== by 0x10AB22: eval_rec (interpreter.c:46) -==7627== by 0x10AB67: eval (interpreter.c:57) -==7627== by 0x1095A4: repl (repl.c:53) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 72 bytes in 1 blocks are still reachable in loss record 27 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4AA1530: _nc_first_db (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AACFA6: _nc_read_entry2 (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AA4018: ??? (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AA43D5: _nc_setupterm (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AA4922: tgetent_sp (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x488E45C: _rl_init_terminal_io (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48700D0: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 78 bytes in 1 blocks are still reachable in loss record 28 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4A9F1FD: ??? (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AA4404: _nc_setupterm (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AA4922: tgetent_sp (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x488E45C: _rl_init_terminal_io (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48700D0: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 106 bytes in 12 blocks are still reachable in loss record 29 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x10D412: ft_strdup (in /dorker_workspace/minishell) -==7627== by 0x10ABEC: getenvlst (env.c:30) -==7627== by 0x109344: main (main.c:26) -==7627== -==7627== 117 (56 direct, 61 indirect) bytes in 1 blocks are definitely lost in loss record 30 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x10D236: ft_split (in /dorker_workspace/minishell) -==7627== by 0x10C32A: get_split_path (env_tools.c:20) -==7627== by 0x10AF78: find_in_path (get_cmd_path.c:70) -==7627== by 0x10ADFF: get_cmd_path (get_cmd_path.c:34) -==7627== by 0x10B720: exec_cmd (execute_cmd.c:96) -==7627== by 0x10B622: execute_cmd (execute_cmd.c:66) -==7627== by 0x10AB22: eval_rec (interpreter.c:46) -==7627== by 0x10AB67: eval (interpreter.c:57) -==7627== by 0x1095A4: repl (repl.c:53) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 156 bytes in 1 blocks are still reachable in loss record 31 of 67 -==7627== at 0x48455EF: calloc (vg_replace_malloc.c:1328) -==7627== by 0x4AAC0CE: _nc_read_termtype (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AACB1A: _nc_read_file_entry (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AACE7C: ??? (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AACFCB: _nc_read_entry2 (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AA4018: ??? (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AA43D5: _nc_setupterm (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AA4922: tgetent_sp (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x488E45C: _rl_init_terminal_io (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48700D0: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== -==7627== 253 bytes in 12 blocks are still reachable in loss record 32 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x10D412: ft_strdup (in /dorker_workspace/minishell) -==7627== by 0x10AC03: getenvlst (env.c:31) -==7627== by 0x109344: main (main.c:26) -==7627== -==7627== 256 bytes in 1 blocks are still reachable in loss record 33 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4870346: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 288 bytes in 12 blocks are still reachable in loss record 34 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x10ABC9: getenvlst (env.c:29) -==7627== by 0x109344: main (main.c:26) -==7627== -==7627== 760 bytes in 1 blocks are still reachable in loss record 35 of 67 -==7627== at 0x48455EF: calloc (vg_replace_malloc.c:1328) -==7627== by 0x4AA437F: _nc_setupterm (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AA4922: tgetent_sp (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x488E45C: _rl_init_terminal_io (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48700D0: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 1,024 bytes in 1 blocks are still reachable in loss record 36 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899377: xrealloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48813DB: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48814E2: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4887916: rl_redisplay (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x486EDFA: readline_internal_setup (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48703AE: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 1,024 bytes in 1 blocks are still reachable in loss record 37 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899377: xrealloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48813F3: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48814E2: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4887916: rl_redisplay (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x486EDFA: readline_internal_setup (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48703AE: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 1,024 bytes in 1 blocks are still reachable in loss record 38 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899377: xrealloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x488140B: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48814E2: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4887916: rl_redisplay (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x486EDFA: readline_internal_setup (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48703AE: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 1,024 bytes in 1 blocks are still reachable in loss record 39 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899377: xrealloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4881423: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48814E2: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4887916: rl_redisplay (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x486EDFA: readline_internal_setup (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48703AE: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 1,024 bytes in 1 blocks are still reachable in loss record 40 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4881535: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4887916: rl_redisplay (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x486EDFA: readline_internal_setup (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48703AE: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 1,024 bytes in 1 blocks are still reachable in loss record 41 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4881550: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4887916: rl_redisplay (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x486EDFA: readline_internal_setup (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48703AE: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 1,024 bytes in 1 blocks are still reachable in loss record 42 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4881568: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4887916: rl_redisplay (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x486EDFA: readline_internal_setup (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48703AE: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 1,024 bytes in 1 blocks are still reachable in loss record 43 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4881580: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4887916: rl_redisplay (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x486EDFA: readline_internal_setup (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48703AE: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 1,536 bytes in 1 blocks are still reachable in loss record 44 of 67 -==7627== at 0x484582F: realloc (vg_replace_malloc.c:1437) -==7627== by 0x489935D: xrealloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4874B84: rl_add_funmap_entry (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4874BCE: rl_initialize_funmap (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48700ED: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 2,032 bytes in 1 blocks are still reachable in loss record 45 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x488E6C9: _rl_init_terminal_io (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48700D0: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 2,272 bytes in 142 blocks are still reachable in loss record 46 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4874B2C: rl_add_funmap_entry (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4874BCE: rl_initialize_funmap (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48700ED: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 3,312 bytes in 1 blocks are still reachable in loss record 47 of 67 -==7627== at 0x48455EF: calloc (vg_replace_malloc.c:1328) -==7627== by 0x4AAC1A9: _nc_read_termtype (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AACB1A: _nc_read_file_entry (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AACE7C: ??? (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AACFCB: _nc_read_entry2 (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AA4018: ??? (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AA43D5: _nc_setupterm (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AA4922: tgetent_sp (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x488E45C: _rl_init_terminal_io (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48700D0: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== -==7627== 3,312 bytes in 1 blocks are still reachable in loss record 48 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4A9F0DE: ??? (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AA4404: _nc_setupterm (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AA4922: tgetent_sp (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x488E45C: _rl_init_terminal_io (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48700D0: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 4,016 bytes in 1 blocks are still reachable in loss record 49 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4892869: add_history (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x109553: repl (repl.c:48) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 4,080 bytes in 1 blocks are still reachable in loss record 50 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x488E6A9: _rl_init_terminal_io (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48700D0: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 4,112 bytes in 1 blocks are still reachable in loss record 51 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4874CBD: rl_make_bare_keymap (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487C3DD: rl_generic_bind (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487D4AD: rl_bind_keyseq_if_unbound_in_map (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x486EBD9: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4870145: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 4,112 bytes in 1 blocks are still reachable in loss record 52 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4874CBD: rl_make_bare_keymap (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487C3DD: rl_generic_bind (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487D4AD: rl_bind_keyseq_if_unbound_in_map (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x486EC7A: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4870145: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 4,112 bytes in 1 blocks are still reachable in loss record 53 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4874CBD: rl_make_bare_keymap (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487C3DD: rl_generic_bind (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487D4AD: rl_bind_keyseq_if_unbound_in_map (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x486EBD9: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4870154: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 4,112 bytes in 1 blocks are still reachable in loss record 54 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4874CBD: rl_make_bare_keymap (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487C3DD: rl_generic_bind (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487D4AD: rl_bind_keyseq_if_unbound_in_map (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x486EC7A: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4870154: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 4,112 bytes in 1 blocks are still reachable in loss record 55 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4874CBD: rl_make_bare_keymap (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487C3DD: rl_generic_bind (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487D4AD: rl_bind_keyseq_if_unbound_in_map (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x486EBD9: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4870179: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 4,112 bytes in 1 blocks are still reachable in loss record 56 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4874CBD: rl_make_bare_keymap (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487C3DD: rl_generic_bind (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487D4AD: rl_bind_keyseq_if_unbound_in_map (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x486EC7A: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4870179: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 7,952 bytes in 1 blocks are still reachable in loss record 57 of 67 -==7627== at 0x48455EF: calloc (vg_replace_malloc.c:1328) -==7627== by 0x4AA07A7: ??? (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AA0F1A: _nc_find_type_entry (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x4AA52B4: tgetstr_sp (in /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4) -==7627== by 0x488E49A: _rl_init_terminal_io (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48700D0: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 8,224 bytes in 2 blocks are still reachable in loss record 58 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4874CBD: rl_make_bare_keymap (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487C3DD: rl_generic_bind (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487D4AD: rl_bind_keyseq_if_unbound_in_map (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x486EC6B: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4870145: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 8,224 bytes in 2 blocks are still reachable in loss record 59 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4874CBD: rl_make_bare_keymap (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487C3DD: rl_generic_bind (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487D4AD: rl_bind_keyseq_if_unbound_in_map (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x486EB62: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4870154: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 8,224 bytes in 2 blocks are still reachable in loss record 60 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4874CBD: rl_make_bare_keymap (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487C3DD: rl_generic_bind (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487D4AD: rl_bind_keyseq_if_unbound_in_map (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x486EB62: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4870179: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 8,224 bytes in 2 blocks are still reachable in loss record 61 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4874CBD: rl_make_bare_keymap (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487C3DD: rl_generic_bind (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487D4AD: rl_bind_keyseq_if_unbound_in_map (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4870193: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 12,336 bytes in 3 blocks are still reachable in loss record 62 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4874CBD: rl_make_bare_keymap (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487C3DD: rl_generic_bind (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487D4AD: rl_bind_keyseq_if_unbound_in_map (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x486EC42: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4870154: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 12,336 bytes in 3 blocks are still reachable in loss record 63 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4874CBD: rl_make_bare_keymap (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487C3DD: rl_generic_bind (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487D4AD: rl_bind_keyseq_if_unbound_in_map (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x486EC6B: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4870154: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 12,336 bytes in 3 blocks are still reachable in loss record 64 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4874CBD: rl_make_bare_keymap (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487C3DD: rl_generic_bind (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487D4AD: rl_bind_keyseq_if_unbound_in_map (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x486EC42: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4870179: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 12,336 bytes in 3 blocks are still reachable in loss record 65 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4874CBD: rl_make_bare_keymap (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487C3DD: rl_generic_bind (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487D4AD: rl_bind_keyseq_if_unbound_in_map (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x486EC6B: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4870179: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 12,336 bytes in 3 blocks are still reachable in loss record 66 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4874CBD: rl_make_bare_keymap (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487C3DD: rl_generic_bind (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487D4AD: rl_bind_keyseq_if_unbound_in_map (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48701A2: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== 41,120 bytes in 10 blocks are still reachable in loss record 67 of 67 -==7627== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7627== by 0x4899338: xmalloc (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x4874CBD: rl_make_bare_keymap (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487C3DD: rl_generic_bind (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487E1BA: rl_parse_and_bind (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487E39C: ??? (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x48700F9: rl_initialize (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x487038A: readline (in /usr/lib/x86_64-linux-gnu/libreadline.so.8.2) -==7627== by 0x1094FF: repl (repl.c:38) -==7627== by 0x109372: main (main.c:28) -==7627== -==7627== LEAK SUMMARY: -==7627== definitely lost: 63 bytes in 2 blocks -==7627== indirectly lost: 61 bytes in 6 blocks -==7627== possibly lost: 0 bytes in 0 blocks -==7627== still reachable: 199,473 bytes in 261 blocks -==7627== suppressed: 0 bytes in 0 blocks -==7627== -==7627== For lists of detected and suppressed errors, rerun with: -s -==7627== ERROR SUMMARY: 5 errors from 5 contexts (suppressed: 0 from 0) -==7626== Invalid read of size 8 -==7626== at 0x1097D1: free_tokens (free_token.c:55) -==7626== by 0x1094C1: free_repl (repl.c:25) -==7626== by 0x1095CB: repl (repl.c:54) -==7626== by 0x109372: main (main.c:28) -==7626== Address 0x4b01c38 is 24 bytes inside a block of size 32 free'd -==7626== at 0x484317B: free (vg_replace_malloc.c:872) -==7626== by 0x109746: free_token (free_token.c:24) -==7626== by 0x10A395: collect_args (parse_cmd.c:91) -==7626== by 0x10A24F: parse_cmd (parse_cmd.c:27) -==7626== by 0x10A12A: parse_statement (parser.c:62) -==7626== by 0x10A07A: parse (parser.c:39) -==7626== by 0x109586: repl (repl.c:51) -==7626== by 0x109372: main (main.c:28) -==7626== Block was alloc'd at -==7626== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7626== by 0x1095F6: new_token (new_token.c:19) -==7626== by 0x109686: new_str_token (new_token.c:36) -==7626== by 0x109C55: snap_string_token (tokenizer.c:79) -==7626== by 0x10A014: tokenizer (tokenizer.c:130) -==7626== by 0x109573: repl (repl.c:50) -==7626== by 0x109372: main (main.c:28) -==7626== -==7626== Invalid read of size 8 -==7626== at 0x1097DD: free_tokens (free_token.c:56) -==7626== by 0x1094C1: free_repl (repl.c:25) -==7626== by 0x1095CB: repl (repl.c:54) -==7626== by 0x109372: main (main.c:28) -==7626== Address 0x4b01c28 is 8 bytes inside a block of size 32 free'd -==7626== at 0x484317B: free (vg_replace_malloc.c:872) -==7626== by 0x109746: free_token (free_token.c:24) -==7626== by 0x10A395: collect_args (parse_cmd.c:91) -==7626== by 0x10A24F: parse_cmd (parse_cmd.c:27) -==7626== by 0x10A12A: parse_statement (parser.c:62) -==7626== by 0x10A07A: parse (parser.c:39) -==7626== by 0x109586: repl (repl.c:51) -==7626== by 0x109372: main (main.c:28) -==7626== Block was alloc'd at -==7626== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7626== by 0x1095F6: new_token (new_token.c:19) -==7626== by 0x109686: new_str_token (new_token.c:36) -==7626== by 0x109C55: snap_string_token (tokenizer.c:79) -==7626== by 0x10A014: tokenizer (tokenizer.c:130) -==7626== by 0x109573: repl (repl.c:50) -==7626== by 0x109372: main (main.c:28) -==7626== -==7626== Invalid free() / delete / delete[] / realloc() -==7626== at 0x484317B: free (vg_replace_malloc.c:872) -==7626== by 0x1097E8: free_tokens (free_token.c:56) -==7626== by 0x1094C1: free_repl (repl.c:25) -==7626== by 0x1095CB: repl (repl.c:54) -==7626== by 0x109372: main (main.c:28) -==7626== Address 0x4b01bd0 is 0 bytes inside a block of size 2 free'd -==7626== at 0x484317B: free (vg_replace_malloc.c:872) -==7626== by 0x1097E8: free_tokens (free_token.c:56) -==7626== by 0x10A08A: parse (parser.c:40) -==7626== by 0x109586: repl (repl.c:51) -==7626== by 0x109372: main (main.c:28) -==7626== Block was alloc'd at -==7626== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7626== by 0x109BCD: snap_string_token (tokenizer.c:68) -==7626== by 0x10A014: tokenizer (tokenizer.c:130) -==7626== by 0x109573: repl (repl.c:50) -==7626== by 0x109372: main (main.c:28) -==7626== -==7626== Invalid free() / delete / delete[] / realloc() -==7626== at 0x484317B: free (vg_replace_malloc.c:872) -==7626== by 0x1097F4: free_tokens (free_token.c:57) -==7626== by 0x1094C1: free_repl (repl.c:25) -==7626== by 0x1095CB: repl (repl.c:54) -==7626== by 0x109372: main (main.c:28) -==7626== Address 0x4b01c20 is 0 bytes inside a block of size 32 free'd -==7626== at 0x484317B: free (vg_replace_malloc.c:872) -==7626== by 0x109746: free_token (free_token.c:24) -==7626== by 0x10A395: collect_args (parse_cmd.c:91) -==7626== by 0x10A24F: parse_cmd (parse_cmd.c:27) -==7626== by 0x10A12A: parse_statement (parser.c:62) -==7626== by 0x10A07A: parse (parser.c:39) -==7626== by 0x109586: repl (repl.c:51) -==7626== by 0x109372: main (main.c:28) -==7626== Block was alloc'd at -==7626== at 0x48407B4: malloc (vg_replace_malloc.c:381) -==7626== by 0x1095F6: new_token (new_token.c:19) -==7626== by 0x109686: new_str_token (new_token.c:36) -==7626== by 0x109C55: snap_string_token (tokenizer.c:79) -==7626== by 0x10A014: tokenizer (tokenizer.c:130) -==7626== by 0x109573: repl (repl.c:50) -==7626== by 0x109372: main (main.c:28) -==7626== - -atic t_assign **collect_assigns(t_token **tokens); -static char **collect_args(t_token **tokens); -static t_assign *to_assign(char *str); -static void set_redir(t_redirection *redir, int type, - char *specifier); - -t_node *parse_cmd(t_token *tokens) -{ - char **args; - t_assign **assigns; - t_redirection *redirs; - - redirs = collect_redirs(&tokens); - assigns = collect_assigns(&tokens); - args = collect_args(&tokens); - return (new_cmd_node(args, assigns, redirs)); -} - -static t_redirection *collect_redirs(t_token **tokens) -{ - t_redirection *result; - t_token *cur; - int idx; - - cur = *tokens; - result = malloc(sizeof(t_redirection) * 2); - if (result == NULL) - { - // free all tokens - return (NULL); - } - set_redir(&result[0], 0, NULL); - set_redir(&result[1], 0, NULL); - while (cur != NULL && cur->next != NULL) - { - if (cur->type == REDIR_TOKEN && cur->next->type == STRING_TOKEN) - { - if (cur->content.redir_type & (INPUT_FILE | INPUT_LIMITER)) - idx = 0; - else if (cur->content.redir_type & (OUTPUT_APPEND | OUTPUT_OVERRIDE)) - idx = 1; - set_redir(&result[idx], cur->content.redir_type, - cur->next->content.string); - cur = cur->next; - free_token_and_connect(cur->previous); - if (cur->next != NULL) - { - cur = cur->next; - free_token_and_connect(cur->previous); - } - else - { - free_token(cur); - } - } - else if (cur->type == REDIR_TOKEN) - { - // err Parsing error - free(result); - return (NULL); - } - else - { - cur = cur->next; - } - } - return (result); -} - -static t_assign **collect_assigns(t_token **tokens) -{ - t_token *cur; - t_assign **result; - int i; - - cur = *tokens; - i = 0; - while (cur != NULL && cur->type == STRING_TOKEN - && cur->content.string[0] != '"' && cur->content.string[0] != '\'' - && ft_strchr(cur->content.string, '=') != NULL) - { - i++; - cur = cur->next; - } - result = malloc(sizeof(t_assign *) * (i + 1)); - if (!result) - { - // free all tokens - return (NULL); - } - cur = *tokens; - i = 0; - while (cur != NULL && cur->type == STRING_TOKEN - && cur->content.string[0] != '"' && cur->content.string[0] != '\'' - && ft_strchr(cur->content.string, '=') != NULL) - { - result[i] = to_assign(cur->content.string); - i++; - cur = cur->next; - free_token(cur->previous); - } - *tokens = cur; - result[i] = NULL; - return (result); -} - -static t_assign *to_assign(char *str) -{ - t_assign *result; - char *split_pos; - - split_pos = ft_strchr(str, '='); - *split_pos = '\0'; - result = malloc(sizeof(t_assign)); - if (result == NULL) - { - return (NULL); - } - result->var = str; - result->value = split_pos + 1; - return (result); -} - -static char **collect_args(t_token **tokens) -{ - t_token *cur; - char **result; - int i; - - cur = *tokens; - i = 0; - while (cur != NULL) - { - i++; - cur = cur->next; - } - result = malloc(sizeof(char *) * (i + 1)); - if (!result) - { - // free all tokens; - return (NULL); - } - cur = *tokens; - i = 0; - while (cur != NULL) - { - result[i] = cur->content.string; - // free token - i++; - cur = cur->next; - } - result[i] = NULL; - return (result); -} - -static void set_redir(t_redirection *redir, int type, char *specifier) -{ - redir->type = type; - redir->specifier = specifier; -} diff --git a/x.c b/x.c deleted file mode 100644 index 4348da1..0000000 --- a/x.c +++ /dev/null @@ -1,528 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* x.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: chuhlig +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/23 12:37:33 by chuhlig #+# #+# */ -/* Updated: 2025/01/23 17:37:13 by chuhlig ### ########.fr */ -/* */ -/* ************************************************************************** */ - -Code Review -init.c -This file initializes the terminal settings and signal handling. It looks correct, but consider checking if tcgetattr and tcsetattr return errors and handle them appropriately. - -C - -static void init_terminal(void) { - struct termios term; - - if (tcgetattr(0, &term) == -1) { - perror("tcgetattr failed"); - exit(EXIT_FAILURE); - } - term.c_lflag &= ~ECHOCTL; - if (tcsetattr(0, TCSANOW, &term) == -1) { - perror("tcsetattr failed"); - exit(EXIT_FAILURE); - } -} -env.c -In the getenvlst function, modifying the environment variable string directly can lead to undefined behavior. Instead, consider using strdup to make a copy of the string. - -C - -void getenvlst(t_env **env, char **en) { - char *tmp; - int i; - t_env *current; - - i = 0; - while (en[i] != NULL) { - tmp = ft_strchr(en[i], '='); - if (!tmp) continue; - *tmp = '\0'; - current = malloc(sizeof(t_env)); - if (!current) exit(EXIT_FAILURE); // Handle malloc failure - current->name = ft_strdup(en[i]); - current->value = ft_strdup(tmp + 1); - current->next = *env; - *env = current; - i++; - } -} -repl.c -The repl function looks good, but consider checking the readline return value for NULL and handling memory allocation errors. - -error.c -The command_not_found_error function should ensure correct file descriptors: - -C - -void command_not_found_error(char *cmd) { - ft_printf("%s:", cmd); - ft_putstr_fd(" command not found", 2); // file descriptor 2 for stderr - ft_printf("\n"); -} -new_node.c -The new_cmd_node function calls free(redirs) but then returns NULL without freeing the allocated node. - -C - -t_node *new_cmd_node(char **args, t_redirection redirs[2], t_list *create_files) { - t_node *node = new_node(CMD_NODE); - if (!node) return NULL; - node->content.cmd.args = args; - if (redirs) { - node->content.cmd.redirs[0] = redirs[0]; - node->content.cmd.redirs[1] = redirs[1]; - node->content.cmd.create_files = create_files; - free(redirs); - redirs = NULL; - return node; - } - free(node); // Free the allocated node - return NULL; -} -free_node.c -In free_cmd_node, ensure you free both redirections correctly. - -C - -static void free_cmd_node(t_node *node) { - int i = 0; - while (node->content.cmd.args && node->content.cmd.args[i]) { - free(node->content.cmd.args[i]); - i++; - } - free(node->content.cmd.args); - if (node->content.cmd.redirs[0].type && node->content.cmd.redirs[0].specifier) - free(node->content.cmd.redirs[0].specifier); - if (node->content.cmd.redirs[1].type && node->content.cmd.redirs[1].specifier) - free(node->content.cmd.redirs[1].specifier); -} -Summary -The provided code generally looks well-structured, but there are some areas where error checking and memory management could be improved. Implementing these suggestions will help make the code more robust and easier to maintain. If you have any specific concerns or files you would like to focus on, please let me know! - - -anything else? -The initial analysis covered some key areas and potential improvements in the provided Makefile and source files. Here are a few more specific suggestions for certain files to ensure robustness and maintainability: - -Additional Suggestions -env.c (Handling Environment Variables): -Error Handling: Add error handling for ft_strdup and malloc to ensure memory allocation was successful. -Environment String Handling: Avoid modifying the original environment strings directly. -C - -void getenvlst(t_env **env, char **en) { - char *tmp; - int i; - t_env *current; - - i = 0; - while (en[i] != NULL) { - tmp = ft_strchr(en[i], '='); - if (!tmp) continue; - *tmp = '\0'; - current = malloc(sizeof(t_env)); - if (!current || !(current->name = ft_strdup(en[i])) || !(current->value = ft_strdup(tmp + 1))) { - perror("malloc or strdup failed"); - exit(EXIT_FAILURE); - } - current->next = *env; - *env = current; - *tmp = '='; // Restore the original string - i++; - } -} -repl.c (Read-Evaluate-Print Loop): -Memory Management: Ensure all allocated memory is freed. -Error Handling: Handle potential errors from functions like readline. -C - -void repl(const char *prompt, t_env **env, int *promptflag) { - char *input; - t_token *token_list; - t_list *lines; - - (*promptflag)++; - while (1) { - input = readline(prompt); - if (input == NULL) { - if (*promptflag > 1) - (*promptflag)--; - printf("exit\n"); - break; - } - if (input[0] == '\0') { - free(input); - continue; - } - add_history(input); - token_list = NULL; - tokenizer(input, &token_list, '\0'); - lines = parse(token_list, env); - if (lines) - set_return_code(eval(lines->content, env), env); - free(input); - free_tokens(token_list); - ft_lstclear(&lines, (void (*)(void *))free_node); - } -} -1 vulnerability detected -get_cmd_path.c (Command Path Resolution): -Error Handling: Ensure errors are correctly handled and resources are freed. -C - -static char *get_absolute_cmd_path(char *cmd, t_env *env, int *return_code) { - char *cur_dir; - char *result; - - cur_dir = ft_strjoin(env_get(env, "PWD"), "/"); - if (!cur_dir) { - return error(ENOMEM, cmd, 127, return_code); - } - result = ft_strjoin(cur_dir, cmd); - free(cur_dir); - if (!result) { - return error(ENOENT, cmd, 127, return_code); - } - if (access(result, F_OK) == -1) { - free(result); - return error(ENOENT, cmd, 127, return_code); - } - if (access(result, X_OK) == -1) { - free(result); - return error(EACCES, cmd, 126, return_code); - } - if (is_directory(result)) { - free(result); - return error(EISDIR, cmd, 126, return_code); - } - return result; -} -General Best Practices: -Consistent Error Handling: Ensure all functions consistently handle errors and free resources appropriately. -Code Comments: Add comments to explain complex logic and improve code readability. -Memory Management: Regularly check for potential memory leaks and ensure all allocated memory is freed. -If you have any specific files or sections you want to dive deeper into, feel free to let me know! - - -ok ill look over it: now after your analyze it seem tokens are not freed properly what i mean with that we are missing it seems on more free but im not sure where to place it especial when the input is invalid and cant be used properly -It looks like you may need to ensure that tokens are properly freed, especially in cases where the input is invalid. Let's take a look at the relevant parts of the code that handle tokens and ensure that memory is managed correctly. - -Token Freeing Logic -To help ensure that tokens are freed properly, let's review the primary functions that deal with token management and identify where additional freeing might be needed. - -Tokenizer Function -The tokenizer function creates tokens. If the input is invalid, we should ensure we free any partially created tokens. - -C - -void tokenizer(char *s, t_token **token_list, char quote_check) { - int pos = 0; - int i = -1; - int f = 0; - while (s[++i]) { - if (!f && ft_strchr("|<>\n", s[i])) - handle_special_chars(s, &i, &pos, token_list); - else if (f && s[i] == quote_check) - f = 0; - else if (!f && ft_strchr("\'\"", s[i])) { - f = 1; - quote_check = s[i]; - } - if ((!f && (ft_isspace(s[i + 1]))) || i == ft_strlen(s) - 1) { - snap_string_token(s, pos, i, token_list); - pos = i + 1; - } - } - *token_list = reverse_token_list(*token_list); -} -Free Tokens Function -The free_tokens function should be used to free the entire token list: - -C - -void free_tokens(t_token *tokens) { - while (tokens != NULL) { - t_token *next = tokens->next; - if (tokens->type == STRING_TOKEN) - free(tokens->content.string); - free(tokens); - tokens = next; - } -} -Parsing Logic -In the parsing logic, ensure that tokens are freed if an error occurs: - -C - -t_list *parse(t_token *tokens, t_env **env) { - t_node *result; - - if (tokens->type == PIPE_TOKEN) { - free_tokens(tokens); // Free tokens if the first token is invalid - return NULL; - } else { - result = parse_statement(tokens, env); - } - if (result == NULL) { - printf("Parsing error.\n"); - free_tokens(tokens); // Free tokens if parsing fails - } - return ft_lstnew(result); -} -Example Fix -Here is a more comprehensive example of how you can ensure tokens are freed correctly in the parse function and the collect_redirs function: - -C - -t_list *parse(t_token *tokens, t_env **env) { - t_node *result; - - if (tokens == NULL || tokens->type == PIPE_TOKEN) { - if (tokens) free_tokens(tokens); // Free tokens if the first token is invalid or NULL - return NULL; - } - result = parse_statement(tokens, env); - if (result == NULL) { - printf("Parsing error.\n"); - free_tokens(tokens); // Free tokens if parsing fails - } - return ft_lstnew(result); -} - -t_redirection *collect_redirs(t_token **tokens, t_env *env, t_list **create_files) { - t_redirection *result; - t_token *cur; - t_minidata data; - - cur = *tokens; - result = malloc(sizeof(t_redirection) * 2); - if (result == NULL) - return free_tokens(*tokens), NULL; - set_redir(&result[0], 0, NULL, env); - set_redir(&result[1], 0, NULL, env); - data.create_files = create_files; - data.env = env; - while (cur != NULL) { - if (cur->type == REDIR_TOKEN && cur->next->type == STRING_TOKEN) - collect_and_check_redir(result, &cur, &data, tokens); - else if (cur->type == REDIR_TOKEN) - return free(result), free_tokens(*tokens), NULL; - else - cur = cur->next; - } - if (cur && cur->type == REDIR_TOKEN) - return free(result), free_tokens(*tokens), NULL; - return result; -} -Summary -By ensuring that tokens are always freed when an error occurs or when they are no longer needed, you can avoid memory leaks and improve the robustness of your shell. If you have specific cases where you suspect tokens are not being freed correctly, please share those, and I can provide more targeted advice! - - -tokens are never NULL except when i press enter but this is handle in repl and to your free token the problem is with our aproach is that parts of the token will be updated while running like in parser.c -Thank you for the clarification. It seems like the tokens are being updated during parsing, which complicates the token freeing process. Let's ensure that we handle token freeing correctly in all cases, especially when errors occur during parsing. - -Reviewing the Token Management -Since tokens are updated during parsing, we need to be careful to free tokens correctly without disrupting the parsing logic. We'll focus on ensuring that tokens are freed appropriately in various scenarios, including error cases. - -Parsing Logic and Freeing Tokens -Parser Function: Ensure that tokens are freed if parsing fails. -Free Tokens Helper Function: Improve the free_tokens function to handle partial frees. -Example Fixes -Free Tokens Function -First, let's have a robust free_tokens function that can handle the complete or partial token lists:' - -C - -void free_tokens(t_token *tokens) { - t_token *next; - while (tokens != NULL) { - next = tokens->next; - if (tokens->type == STRING_TOKEN && tokens->content.string != NULL) { - free(tokens->content.string); - } - free(tokens); - tokens = next; - } -} -Parsing Functions -Next, ensure that the parsing logic properly frees tokens if an error occurs: - -parse Function: -C - -t_list *parse(t_token *tokens, t_env **env) { - t_node *result; - - if (tokens == NULL || tokens->type == PIPE_TOKEN) { - if (tokens) free_tokens(tokens); // Free tokens if the first token is invalid or NULL - return NULL; - } - result = parse_statement(tokens, env); - if (result == NULL) { - printf("Parsing error.\n"); - free_tokens(tokens); // Free tokens if parsing fails - } - return ft_lstnew(result); -} -parse_statement Function: -C - -static t_node *parse_statement(t_token *tokens, t_env **env) { - t_token *left_side_tokens; - - left_side_tokens = split_at_first(&tokens, PIPE_TOKEN); - if (left_side_tokens == NULL) { - free_tokens(tokens); // Free remaining tokens if split fails - return NULL; - } - if (tokens != NULL) { - t_node *left_node = parse_cmd(left_side_tokens, env); - t_node *right_node = parse_statement(tokens, env); - if (left_node == NULL || right_node == NULL) { - free_tokens(left_side_tokens); - free_tokens(tokens); - return NULL; - } - return new_pipe_node(left_node, right_node); - } - return parse_cmd(left_side_tokens, env); -} -Handling Token Updates -When tokens are updated, ensure that the old parts are freed correctly before being replaced. For example: - -C - -void update_token(t_token *token, int new_type, char *new_content) { - if (token->type == STRING_TOKEN && token->content.string != NULL) { - free(token->content.string); - } - token->type = new_type; - token->content.string = new_content; -} -Summary -By ensuring that tokens are properly freed in all scenarios, including when parsing errors occur and when tokens are updated, you can avoid memory leaks and ensure robust memory management. If you have any specific cases or additional concerns, please let me know! - - -i never update tokens static char **collect_args(t_token **tokens, t_env **env) { t_token *cur; char **result; int i; t_token *next; cur = *tokens; i = 0; while (cur != NULL && ++i) cur = cur->next; result = malloc(sizeof(char *) * (i + 1)); if (result == NULL) return (free_tokens(*tokens), NULL); cur = *tokens; i = 0; while (cur != NULL && cur->type == STRING_TOKEN) { next = cur->next; if (cur->previous) free_token(cur->previous); result[i] = format_string(cur->content.string, *env, ft_atoi("0")); i++; if (cur->next == NULL) free_token(cur); cur = next; } result[i] = NULL; return (result); } any suggestions for this? static char **collect_args(t_token **tokens, t_env **env) { t_token *cur; char **result; int i; t_token *next; cur = *tokens; i = 0; while (cur != NULL && ++i) cur = cur->next; result = malloc(sizeof(char *) * (i + 1)); if (result == NULL) return (free_tokens(*tokens), NULL); cur = *tokens; i = 0; while (cur != NULL && cur->type == STRING_TOKEN) { next = cur->next; if (cur->previous) free_token(cur->previous); result[i] = format_string(cur->content.string, *env, ft_atoi("0")); i++; if (cur->next == NULL) free_token(cur); cur = next; } result[i] = NULL; return (result); } just take as example input : a and check the hole code for yourself -Let's take a closer look at the collect_args function to ensure that tokens are freed properly and memory is managed correctly. The goal is to collect arguments from tokens, format them, and ensure that all tokens are freed without causing memory leaks or dangling pointers. - -Review of collect_args -The function collect_args traverses the token list, collects string tokens, and formats them into an array of arguments. It also attempts to free tokens as it processes them. - -Here’s the function with comments and suggestions for improvement:' - -C - -static char **collect_args(t_token **tokens, t_env **env) { - t_token *cur; - char **result; - int i; - t_token *next; - - // Count the number of tokens - cur = *tokens; - i = 0; - while (cur != NULL && ++i) - cur = cur->next; - - // Allocate memory for the result array - result = malloc(sizeof(char *) * (i + 1)); - if (result == NULL) { - free_tokens(*tokens); // Free tokens if memory allocation fails - return NULL; - } - - // Collect and format string tokens - cur = *tokens; - i = 0; - while (cur != NULL && cur->type == STRING_TOKEN) { - next = cur->next; - if (cur->previous) - free_token(cur->previous); // Free the previous token - - result[i] = format_string(cur->content.string, *env, 0); - if (result[i] == NULL) { // Check if format_string failed - free_tokens(next); // Free remaining tokens - while (i > 0) { - free(result[--i]); - } - free(result); - return NULL; - } - - i++; - if (cur->next == NULL) - free_token(cur); // Free the current token if it's the last one - cur = next; - } - result[i] = NULL; - return result; -} -Improvements and Error Handling -Error Handling: Improved error handling by checking if format_string failed and freeing the remaining tokens and allocated memory. -Memory Allocation Check: Ensured that memory allocation failures for result and format_string are handled. -Freeing Tokens: Ensured that tokens are properly freed, including the current token if it's the last one. -Example Input: "a" -For the input "a", the function should create a single argument "a" and ensure that all tokens are freed. - -Updated Function -Here’s the updated function with the improvements: - -C' - -static char **collect_args(t_token **tokens, t_env **env) { - t_token *cur; - char **result; - int i; - t_token *next; - - // Count the number of tokens - cur = *tokens; - i = 0; - while (cur != NULL && ++i) - cur = cur->next; - - // Allocate memory for the result array - result = malloc(sizeof(char *) * (i + 1)); - if (result == NULL) { - free_tokens(*tokens); // Free tokens if memory allocation fails - return NULL; - } - - // Collect and format string tokens - cur = *tokens; - i = 0; - while (cur != NULL && cur->type == STRING_TOKEN) { - next = cur->next; - if (cur->previous) - free_token(cur->previous); // Free the previous token - - result[i] = format_string(cur->content.string, *env, 0); - if (result[i] == NULL) { // Check if format_string failed - free_tokens(next); // Free remaining tokens - while (i > 0) { - free(result[--i]); - } - free(result); - return NULL; - } - - i++; - if (cur->next == NULL) - free_token(cur); // Free the current token if it's the last one - cur = next; - } - result[i] = NULL; - return result; -} - - -tendenziel sollte in collect arg free token until - -parse ist das erste was nach token passiert und da wird token zu node umgewandelt \ No newline at end of file