jdagz28 / Minishell

0 stars 0 forks source link

Valgrind and fsanitize checks #56

Closed jdagz28 closed 11 months ago

jdagz28 commented 11 months ago

Signal Uninitialised.

==30714== Syscall param rt_sigaction(act->sa_mask) points to uninitialised byte(s)
==30714==    at 0x49049E3: __libc_sigaction (libc_sigaction.c:58)
==30714==    by 0x10FA84: signal_set (signal.c:34)
==30714==    by 0x10AFE9: exec_bin (exec_bin.c:54)
==30714==    by 0x10B4E3: exec_simple (exec.c:71)
==30714==    by 0x10B5AD: shell_exec (exec.c:94)
==30714==    by 0x10F43C: shell_prompt (shell_prompt.c:74)
==30714==    by 0x10F602: shell_run (shell.c:60)
==30714==    by 0x10FAFA: main (minishell.c:25)
==30714==  Address 0x1ffefff7a8 is on thread 1's stack
==30714==  in frame #0, created by __libc_sigaction (libc_sigaction.c:43)
==30714== 

-fixed: added sigemptyset() in signal_set

jdagz28 commented 11 months ago

leaks in SHLVL

int shell_init_level(t_shell* shell)
{
    char* line;
    char* res;
    char* level;
    int value;
    int len;

    line = env_get("SHLVL=", 0, shell->env);
    if (!line)
        return(EXIT_FAILURE);
    value = ft_atoi(line);
    level = ft_itoa(value + 1);
    free(line);
    len = ft_strlen("SHLVL=") + ft_strlen(level) + 1;
    res = malloc(sizeof(char) * len);
    if (!res)
        return(EXIT_FAILURE);
    ft_strlcpy(res, "SHLVL=", len);
    ft_strlcat(res, level, len);
    export(shell, res);
    **free(level);
    free(res);**
    return(EXIT_SUCCESS);
}

--fixed

jdagz28 commented 11 months ago

fixed leaks in env_gepath; used ft_splitfree() instead of free()


char    *env_getpath(char *str, char **env)
{
    int     i;
    char    *res;
    char    **paths;

    paths = env_get_bin_paths(env);
    if (!paths)
        return (NULL);
    i = 0;
    while (paths[i])
    {
        res = env_trypath(paths[i], str);
        if (res)
            break ;
        i++;
    }
    **ft_splitfree(paths);**
    return (res);
}
jdagz28 commented 11 months ago

fixed leaks in freeing tokens. free by consuming tokens while building the ast.