Fix memory leak - not freeing string holding path
authorLukas Jiriste <ljiriste@student.42prague.com>
Fri, 13 Oct 2023 13:39:06 +0000 (15:39 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Fri, 13 Oct 2023 13:39:06 +0000 (15:39 +0200)
src/main.c

index 68a38ecaaca814fc440879d0c0487083a823309b..da1fa1cc28bbdf5280867dc584804536f37eb0c5 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2023/10/12 14:52:24 by ljiriste          #+#    #+#             */
-/*   Updated: 2023/10/13 13:54:26 by ljiriste         ###   ########.fr       */
+/*   Updated: 2023/10/13 15:36:37 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -36,6 +36,7 @@ int   my_open(const char *fname)
        path = ft_strdup(TEST_DIR);
        ft_strncat_alloc(&path, fname, ft_strlen(fname));
        fd = open(path, O_RDONLY);
+       free(path);
        return (fd);
 }
 
@@ -56,6 +57,7 @@ int   create_res_file(const char *fname)
        path = ft_strdup(RESULT_DIR);
        ft_strncat_alloc(&path, fname, ft_strlen(fname));
        fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+       free(path);
        return (fd);
 }