Browse Source

[enh] herething: better handling mleaks.

Moul 3 years ago
parent
commit
6a1981c4dd
1 changed files with 6 additions and 6 deletions
  1. 6 6
      src/herething.c

+ 6 - 6
src/herething.c

@@ -36,7 +36,8 @@ void	exec_herething(t_e *e, int pos, char *fc)
 	char	**cmd;
 
 	cmd = (char**)malloc(sizeof(char*) * 3);
-	cmd[0] = ft_strtrim(ft_strdup_till(e->cmd, fc[0]));
+	cmd[0] = ft_strdup_till(e->cmd, fc[0]);
+	cmd[0] = ft_assign_free_str(cmd[0], ft_strtrim);
 	cmd[1] = prompt_herething(e, pos, fc);
 	cmd[2] = NULL;
 	ft_strdel(&e->cmd);
@@ -58,18 +59,17 @@ char	*prompt_herething(t_e *e, int pos, char *fc)
 	char	*txt;
 
 	h = (t_e*)malloc(sizeof(t_e));
-	h->cmd = ft_strnew(1);
+	h->cmd = ft_strnew(0);
 	txt = ft_strdup(fc);
 	while (ft_strchr(h->cmd, e->par_close[pos]) == NULL)
 	{
-		txt = ft_strjoinf(txt, ft_strjoinf(h->cmd, "\n", 1), 1);
-		h->cmd = ft_strdup("");
+		txt = ft_strjoinf(txt, ft_strjoinf(h->cmd, "\n", 1), 3);
+		h->cmd = ft_strnew(0);
 		ft_putstr("\n>");
 		here_edition(h, 0);
 	}
 	ft_putchar('\n');
-	txt = ft_strjoinf(txt, h->cmd, 1);
-	ft_strdel(&h->cmd);
+	txt = ft_strjoinf(txt, h->cmd, 3);
 	free(h);
 	return (txt);
 }