oooooorriiiii / minishell

2 stars 1 forks source link

minishellの中でbashを実行するとleakする #62

Open oooooorriiiii opened 2 years ago

oooooorriiiii commented 2 years ago
ymori@ubuntu:~/42/minishell$ ./minishell 
minishell> bash
ymori@ubuntu:~/42/minishell$ exit
exit
minishell> exit
exit

=================================================================
==9067==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 14 byte(s) in 1 object(s) allocated from:
    #0 0x7f6a21d1ebc8 in malloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10dbc8)
    #1 0x557689679c20 in ft_strdup (/home/ymori/42/minishell/minishell+0x42c20)
    #2 0x557689679249 in is_cmd_exist srcs/execute/path_utils.c:44
    #3 0x5576896780f4 in search_cmd srcs/execute/path_add.c:54
    #4 0x5576896783f9 in search_cmd_path srcs/execute/path_add.c:80
    #5 0x557689678627 in add_path srcs/execute/path_add.c:104
    #6 0x55768966dbfe in execute_simple_command srcs/execute/execute_simple_command.c:33
    #7 0x55768966e4f1 in execute_command srcs/execute/execute_simple_command.c:71
    #8 0x5576896715cc in execute_job srcs/execute/execute.c:57
    #9 0x557689671614 in execute_cmdline srcs/execute/execute.c:66
    #10 0x557689671674 in execute_syntax_tree srcs/execute/execute.c:77
    #11 0x55768965fc30 in minishell_loop srcs/main.c:61
    #12 0x5576896603ef in main srcs/main.c:118
    #13 0x7f6a210890b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)

SUMMARY: AddressSanitizer: 14 byte(s) leaked in 1 allocation(s).
SoichiroSugimoto commented 2 years ago
void    execute_simple_command(t_astree *simple_cmd_node, t_cmd_args *args)
{
    char    *path;

    init_command_struct(simple_cmd_node, args);
    // print_allstruct(args);
    if (!check_builtin(args->cmdpath[0]))
    {
        path = add_path(args);
        if (access(path, X_OK) == -1)
            g_minishell.exit_status = 126;
        if (!path)
            g_minishell.exit_status = 127;
        free_str(&path);
    }
    if (joudge_process(args) == 1)
        execute_in_parent(args);
    else
        execute_in_child(args);
    destroy_command_struct(args);
}