Skip to content

Commit

Permalink
fixed leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoommus committed Aug 6, 2018
1 parent c34be37 commit 260a1c8
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 16 deletions.
3 changes: 0 additions & 3 deletions include/minishell.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ typedef int (*t_builtin_func) (char **);
/*
** Builtins
*/
int hs_alias(char **args);
int hs_cd(char **args);
int hs_echo(char **args);
int hs_env(char **args);
Expand All @@ -47,7 +46,6 @@ int hs_exit(char **args);
int hs_where(char **args);

static char *g_builtins[] = {
"alias",
"cd",
"echo",
"env",
Expand All @@ -60,7 +58,6 @@ static char *g_builtins[] = {
};

static t_builtin_func g_builtin_func[] = {
&hs_alias,
&hs_cd,
&hs_echo,
&hs_env,
Expand Down
2 changes: 0 additions & 2 deletions libft/ft_strdup.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ char *ft_strdup(const char *src)
copy = (char *)malloc(sizeof(char) * (l + 1));
if (copy == 0)
return (0);
if (src == NULL)
return (ft_strnew(0));
while (src[i])
{
copy[i] = src[i];
Expand Down
10 changes: 2 additions & 8 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,16 @@ int hs_echo(char **args)
return (0);
}

int hs_alias(char **args)
{
*args = args[0];
return (0);
}

int hs_help(char **args)
{
int i;

*args = args[0];
ft_printf("Existing builtins:\n");
i = 0;
while (i < 9)
while (i < 8)
ft_printf("%s, ", g_builtins[i++]);
ft_printf("%s\n", g_builtins[9]);
ft_printf("%s\n", g_builtins[8]);
return (0);
}

Expand Down
2 changes: 1 addition & 1 deletion src/cd.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ int hs_cd(char **args)
char pwd[1024];
int status;

swap = ft_strdup(args[0]);
swap = args[0] == NULL ? ft_strnew(0) : ft_strdup(args[0]);
oldpwd = get_env("OLDPWD");
getcwd(currpwd, 1024);
status = try_cd(swap, oldpwd);
Expand Down
2 changes: 1 addition & 1 deletion src/commands_execution.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int try_builtin(char *builtin, char **args)
int i;

i = 0;
while (i < 10 && builtin)
while (i < 9 && builtin)
{
if (ft_strcmp(builtin, g_builtins[i]) == 0)
return (g_builtin_func[i](args));
Expand Down
2 changes: 1 addition & 1 deletion src/environ_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ char *get_env(char *name)
if (ABS(ft_strcmp(name, g_environ[i])) == '=')
{
swap = ft_strsplit(g_environ[i], '=');
dummy = ft_strdup(swap[1]);
dummy = swap[1] == NULL ? ft_strnew(0) : ft_strdup(swap[1]);
free_array(swap);
break ;
}
Expand Down

0 comments on commit 260a1c8

Please sign in to comment.