6
6
/* By: cdomet-d <cdomet-d@student.42lyon.fr> +#+ +:+ +#+ */
7
7
/* +#+#+#+#+#+ +#+ */
8
8
/* Created: 2024/04/12 11:51:17 by cdomet-d #+# #+# */
9
- /* Updated: 2024/05/21 16:54:54 by cdomet-d ### ########lyon.fr */
9
+ /* Updated: 2024/05/24 13:29:38 by cdomet-d ### ########lyon.fr */
10
10
/* */
11
11
/* ************************************************************************** */
12
12
@@ -59,17 +59,19 @@ static char *gen_filename(int fn)
59
59
if (!strfn )
60
60
return (print_error (errno , "minishell: heredoc" ));
61
61
filename = ft_strjoin ("/tmp/tmp_" , strfn );
62
+ free (strfn );
62
63
if (!filename )
63
64
return (print_error (errno , "minishell: heredoc" ));
64
- free (strfn );
65
65
return (filename );
66
66
}
67
67
68
68
static void * create_hfile (t_fd * fd , t_input * tmp , char * filename )
69
69
{
70
+ if (!filename )
71
+ return (NULL );
70
72
fd -> hfd = open (filename , O_CREAT | O_TRUNC | O_RDWR , 0644 );
71
73
if (fd -> hfd == -1 )
72
- return (print_error (errno , "minishell: heredoc" ));
74
+ return (free ( filename ), print_error (errno , "minishell: heredoc" ));
73
75
if (!h_rl (fd -> hfd , tmp ))
74
76
return (free (filename ), close (fd -> hfd ), NULL );
75
77
free (filename );
@@ -90,13 +92,19 @@ void *create_hdocs(t_fd *fd, t_input *in)
90
92
while (op_true (tmp , heredoc ))
91
93
{
92
94
if (!create_hfile (fd , tmp , gen_filename (fn )))
95
+ {
96
+ free (tmp -> data [0 ]);
97
+ tmp -> data [0 ] = NULL ;
93
98
return (NULL );
99
+ }
94
100
free (tmp -> data [0 ]);
95
101
in -> status = tmp -> status ;
96
102
tmp -> data [0 ] = gen_filename (fn );
103
+ if (!tmp -> data [0 ])
104
+ return (NULL );
97
105
tmp = find_here (tmp , true);
98
106
fn ++ ;
99
107
}
100
- set_status (in , 0 );
108
+ set_status (in , * fd , 0 );
101
109
return ((int * ) true);
102
110
}
0 commit comments