Fixed small leaks
This commit is contained in:
parent
d9eb6eed00
commit
dc9005218c
9 changed files with 35 additions and 28 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/30 16:24:53 by rparodi #+# #+# */
|
||||
/* Updated: 2024/07/30 16:25:23 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/08/05 15:19:12 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -59,6 +59,9 @@ void close_dir(t_dir *dir)
|
|||
return ;
|
||||
if (closedir(dir->ptr) == -1)
|
||||
return ;
|
||||
if (dir->name != NULL)
|
||||
mem_free(dir->name);
|
||||
slot = (void *)(dir)-offsetof(struct s_file_slot, slot.dir);
|
||||
mem_set_zero(slot, sizeof(*slot));
|
||||
slot->ty = SLOT_UNUSED;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/30 16:17:17 by rparodi #+# #+# */
|
||||
/* Updated: 2024/07/30 16:23:47 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/08/05 15:19:17 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -99,6 +99,9 @@ void close_fd(t_fd *fd)
|
|||
return ;
|
||||
if (close(fd->fd) == -1)
|
||||
return ;
|
||||
if (fd->name != NULL)
|
||||
mem_free(fd->name);
|
||||
slot = (void *)(fd)-offsetof(struct s_file_slot, slot.fd);
|
||||
mem_set_zero(slot, sizeof(*slot));
|
||||
slot->ty = SLOT_UNUSED;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/30 16:26:32 by rparodi #+# #+# */
|
||||
/* Updated: 2024/07/30 16:27:06 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/08/05 15:19:21 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -76,6 +76,9 @@ void close_file(t_file *file)
|
|||
return ;
|
||||
if (fclose(file->ptr) == -1)
|
||||
return ;
|
||||
if (file->name != NULL)
|
||||
mem_free(file->name);
|
||||
slot = (void *)(file)-offsetof(struct s_file_slot, slot.file);
|
||||
mem_set_zero(slot, sizeof(*slot));
|
||||
slot->ty = SLOT_UNUSED;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 15:53:50 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/07/30 16:28:09 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/08/05 15:18:22 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -64,11 +64,11 @@ void close_slot(struct s_file_slot *slot)
|
|||
if (slot->ty == SLOT_UNUSED)
|
||||
;
|
||||
else if (slot->ty == SLOT_FD)
|
||||
(mem_free(slot->slot.fd.name), close_fd(&slot->slot.fd));
|
||||
close_fd(&slot->slot.fd);
|
||||
else if (slot->ty == SLOT_DIR)
|
||||
(mem_free(slot->slot.dir.name), close_dir(&slot->slot.dir));
|
||||
close_dir(&slot->slot.dir);
|
||||
else if (slot->ty == SLOT_FILE)
|
||||
(mem_free(slot->slot.file.name), close_file(&slot->slot.file));
|
||||
close_file(&slot->slot.file);
|
||||
else
|
||||
(void)!write(2, "Unknown SLOT type", 17);
|
||||
mem_set_zero(slot, sizeof(*slot));
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/07 13:08:52 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/07/10 17:54:22 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/08/05 15:14:46 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -22,5 +22,6 @@
|
|||
void me_exit(t_i32 exit_code)
|
||||
{
|
||||
(get_stdin(), get_stdout(), get_stderr());
|
||||
close_all_slots();
|
||||
exit(exit_code);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue