Fix not freeing filename
authorLukas Jiriste <ljiriste@student.42prague.com>
Thu, 1 Aug 2024 07:48:48 +0000 (09:48 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Thu, 1 Aug 2024 07:48:48 +0000 (09:48 +0200)
src/execution.c

index 18effc9cfd9fb5bf19350e230a7fe334c94b92f9..ce5ea5352fb62358f68cf431960a4cebdf75e405 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/07/21 08:57:54 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/08/01 09:28:18 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/08/01 09:47:44 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -135,7 +135,10 @@ int        add_redirection_file(t_vec *redirections, t_parse_tree_node *io_file, int fd
                        fd = STDIN_FILENO;
                sec_fd = open(filename, O_RDONLY);
                if (sec_fd < 0)
+               {
+                       free(filename);
                        return (1);
+               }
                redir = (t_redirection){.from_to_fds[0] = sec_fd, .from_to_fds[1] = fd, .created = 0};
        }
        else
@@ -147,9 +150,13 @@ int        add_redirection_file(t_vec *redirections, t_parse_tree_node *io_file, int fd
                else
                        sec_fd = open(filename, O_CREAT | O_WRONLY | O_APPEND, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH);
                if (sec_fd == -1)
+               {
+                       free(filename);
                        return (1);
+               }
                redir = (t_redirection){.from_to_fds[0] = fd, .from_to_fds[1] = sec_fd, .created = 1};
        }
+       free(filename);
        return (ft_vec_append(redirections, &redir) != success);
 }