Fixed small leaks
This commit is contained in:
parent
d9eb6eed00
commit
dc9005218c
9 changed files with 35 additions and 28 deletions
2
Makefile
2
Makefile
|
|
@ -6,7 +6,7 @@
|
||||||
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
|
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
|
||||||
# Updated: 2024/08/04 14:28:29 by maiboyer ### ########.fr #
|
# Updated: 2024/08/05 14:52:59 by maiboyer ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/24 15:45:08 by maiboyer #+# #+# */
|
/* Created: 2024/07/24 15:45:08 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/07/24 16:02:04 by maiboyer ### ########.fr */
|
/* Updated: 2024/08/05 15:13:17 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -24,7 +24,7 @@ struct s_expandable_str {
|
||||||
|
|
||||||
static inline void free_expandable_str(t_expandable_str self)
|
static inline void free_expandable_str(t_expandable_str self)
|
||||||
{
|
{
|
||||||
void mem_free(void *ptr);
|
void mem_free(void *str);
|
||||||
|
|
||||||
mem_free(self.value);
|
mem_free(self.value);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/11 17:22:29 by maiboyer #+# #+# */
|
/* Created: 2024/07/11 17:22:29 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/08/03 16:20:04 by maiboyer ### ########.fr */
|
/* Updated: 2024/08/05 15:29:40 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -196,7 +196,7 @@ t_error _ast_get_str__raw__no_quote(t_ast_node elem, t_word_iterator *state, t_v
|
||||||
last_backslash = true;
|
last_backslash = true;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return (vec_estr_push(out, (t_expandable_str){.do_expand = false, .value = str_clone(ret.buf)}), NO_ERROR);
|
return (vec_estr_push(out, (t_expandable_str){.do_expand = false, .value = ret.buf}), NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
t_error _ast_get_str__raw__single_quote(t_ast_node elem, t_word_iterator *state, t_vec_estr *out)
|
t_error _ast_get_str__raw__single_quote(t_ast_node elem, t_word_iterator *state, t_vec_estr *out)
|
||||||
|
|
@ -211,7 +211,7 @@ t_error _ast_get_str__raw__single_quote(t_ast_node elem, t_word_iterator *state,
|
||||||
while (elem->data.raw_string.str[i])
|
while (elem->data.raw_string.str[i])
|
||||||
string_push_char(&ret, elem->data.raw_string.str[i++]);
|
string_push_char(&ret, elem->data.raw_string.str[i++]);
|
||||||
string_pop(&ret);
|
string_pop(&ret);
|
||||||
return (vec_estr_push(out, (t_expandable_str){.do_expand = false, .value = str_clone(ret.buf)}), NO_ERROR);
|
return (vec_estr_push(out, (t_expandable_str){.do_expand = false, .value = ret.buf}), NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
t_error _ast_get_str__raw__double_quote(t_ast_node elem, t_word_iterator *state, t_vec_estr *out)
|
t_error _ast_get_str__raw__double_quote(t_ast_node elem, t_word_iterator *state, t_vec_estr *out)
|
||||||
|
|
@ -234,7 +234,7 @@ t_error _ast_get_str__raw__double_quote(t_ast_node elem, t_word_iterator *state,
|
||||||
last_backslash = true;
|
last_backslash = true;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return (vec_estr_push(out, (t_expandable_str){.do_expand = false, .value = str_clone(ret.buf)}), NO_ERROR);
|
return (vec_estr_push(out, (t_expandable_str){.do_expand = false, .value = ret.buf}), NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
t_error _ast_get_str__raw(t_ast_node elem, t_word_iterator *state, t_vec_estr *out)
|
t_error _ast_get_str__raw(t_ast_node elem, t_word_iterator *state, t_vec_estr *out)
|
||||||
|
|
@ -396,7 +396,7 @@ t_error _word_into_str(t_ast_node self, t_state *state, t_vec_str *append)
|
||||||
{
|
{
|
||||||
ifs = _get_ifs_value(state);
|
ifs = _get_ifs_value(state);
|
||||||
if (str_split(res.value.buffer[i].value, ifs, &splitted))
|
if (str_split(res.value.buffer[i].value, ifs, &splitted))
|
||||||
return (ERROR);
|
return (vec_estr_free(res.value), ERROR);
|
||||||
if (!vec_str_pop_front(&splitted, &tmp_str))
|
if (!vec_str_pop_front(&splitted, &tmp_str))
|
||||||
{
|
{
|
||||||
if (str_find_chr(ifs, res.value.buffer[i].value[0]) == NULL)
|
if (str_find_chr(ifs, res.value.buffer[i].value[0]) == NULL)
|
||||||
|
|
@ -414,7 +414,7 @@ t_error _word_into_str(t_ast_node self, t_state *state, t_vec_str *append)
|
||||||
while (j + 1 < splitted.len)
|
while (j + 1 < splitted.len)
|
||||||
{
|
{
|
||||||
if (vec_str_pop_front(&splitted, &tmp_str))
|
if (vec_str_pop_front(&splitted, &tmp_str))
|
||||||
return (ERROR);
|
return (vec_estr_free(res.value), ERROR);
|
||||||
vec_str_push(append, tmp_str);
|
vec_str_push(append, tmp_str);
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
|
|
@ -438,6 +438,7 @@ t_error _word_into_str(t_ast_node self, t_state *state, t_vec_str *append)
|
||||||
string_push(&tmp, res.value.buffer[i++].value);
|
string_push(&tmp, res.value.buffer[i++].value);
|
||||||
vec_str_push(append, tmp.buf);
|
vec_str_push(append, tmp.buf);
|
||||||
}
|
}
|
||||||
|
vec_estr_free(res.value);
|
||||||
return (NO_ERROR);
|
return (NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -484,9 +485,6 @@ t_error run_until(t_ast_until *until, t_state *state, void *out) NOT_DONE;
|
||||||
t_error run_variable_assignment(t_ast_variable_assignment *variable_assignment, t_state *state, bool is_temporary, void *out) NOT_DONE;
|
t_error run_variable_assignment(t_ast_variable_assignment *variable_assignment, t_state *state, bool is_temporary, void *out) NOT_DONE;
|
||||||
t_error run_while_(t_ast_while *while_, t_state *state, void *out) NOT_DONE;
|
t_error run_while_(t_ast_while *while_, t_state *state, void *out) NOT_DONE;
|
||||||
|
|
||||||
/// TODO: remove this
|
|
||||||
void mem_free(void *ptr);
|
|
||||||
|
|
||||||
t_error run_program(t_ast_program *self, t_state *state, t_program_result *out)
|
t_error run_program(t_ast_program *self, t_state *state, t_program_result *out)
|
||||||
{
|
{
|
||||||
t_usize i;
|
t_usize i;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */
|
/* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */
|
||||||
/* Updated: 2024/08/04 16:39:16 by rparodi ### ########.fr */
|
/* Updated: 2024/08/05 14:50:22 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -85,11 +85,11 @@ void print_node_data(t_node *t, t_usize depth)
|
||||||
idx = 0;
|
idx = 0;
|
||||||
if (t->kind == 7)
|
if (t->kind == 7)
|
||||||
return;
|
return;
|
||||||
printf("\x1b[%im[%-6s](%llu)\x1b[0m", t->field_str == NULL ? 90 : 32, t->field_str == NULL ? "nil" : t->field_str, t->field);
|
printf("\x1b[%im[%-6s](%lu)\x1b[0m", t->field_str == NULL ? 90 : 32, t->field_str == NULL ? "nil" : t->field_str, t->field);
|
||||||
while (idx++ < depth + 1)
|
while (idx++ < depth + 1)
|
||||||
printf("\t");
|
printf("\t");
|
||||||
idx = 0;
|
idx = 0;
|
||||||
printf("%s(%llu) = %s\n", t->kind_str, t->kind, node_getstr(t));
|
printf("%s(%lu) = %s\n", t->kind_str, t->kind, node_getstr(t));
|
||||||
while (idx < t->childs_count)
|
while (idx < t->childs_count)
|
||||||
print_node_data(&t->childs[idx++], depth + 1);
|
print_node_data(&t->childs[idx++], depth + 1);
|
||||||
}
|
}
|
||||||
|
|
@ -103,7 +103,6 @@ t_node parse_str(t_state *state)
|
||||||
|
|
||||||
tree = ts_parser_parse_string(state->parser, NULL, state->str_input, str_len(state->str_input));
|
tree = ts_parser_parse_string(state->parser, NULL, state->str_input, str_len(state->str_input));
|
||||||
node = ts_tree_root_node(tree);
|
node = ts_tree_root_node(tree);
|
||||||
printf("BUILDING AST\n");
|
|
||||||
if (ast_from_node(node, state->str_input, &out))
|
if (ast_from_node(node, state->str_input, &out))
|
||||||
(state->ast = NULL, printf("Error when building node\n"));
|
(state->ast = NULL, printf("Error when building node\n"));
|
||||||
else
|
else
|
||||||
|
|
@ -115,13 +114,13 @@ t_node parse_str(t_state *state)
|
||||||
|
|
||||||
void exec_shcat(t_state *state)
|
void exec_shcat(t_state *state)
|
||||||
{
|
{
|
||||||
/* t_program_result prog_res; */
|
t_program_result prog_res;
|
||||||
/* */
|
/* */
|
||||||
/* prog_res = (t_program_result){.exit = 0}; */
|
prog_res = (t_program_result){.exit = 0};
|
||||||
print_node_data(&state->current_node, 0);
|
print_node_data(&state->current_node, 0);
|
||||||
free_node(state->current_node);
|
free_node(state->current_node);
|
||||||
/* if (state->ast != NULL && run_program(&state->ast->data.program, state, &prog_res)) */
|
if (state->ast != NULL && run_program(&state->ast->data.program, state, &prog_res))
|
||||||
/* printf("Error when execting the Command \n"); */
|
printf("Error when execting the Command \n");
|
||||||
ast_free(state->ast);
|
ast_free(state->ast);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/30 16:24:53 by rparodi #+# #+# */
|
/* 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 ;
|
return ;
|
||||||
if (closedir(dir->ptr) == -1)
|
if (closedir(dir->ptr) == -1)
|
||||||
return ;
|
return ;
|
||||||
|
if (dir->name != NULL)
|
||||||
|
mem_free(dir->name);
|
||||||
slot = (void *)(dir)-offsetof(struct s_file_slot, slot.dir);
|
slot = (void *)(dir)-offsetof(struct s_file_slot, slot.dir);
|
||||||
mem_set_zero(slot, sizeof(*slot));
|
mem_set_zero(slot, sizeof(*slot));
|
||||||
|
slot->ty = SLOT_UNUSED;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/30 16:17:17 by rparodi #+# #+# */
|
/* 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 ;
|
return ;
|
||||||
if (close(fd->fd) == -1)
|
if (close(fd->fd) == -1)
|
||||||
return ;
|
return ;
|
||||||
|
if (fd->name != NULL)
|
||||||
|
mem_free(fd->name);
|
||||||
slot = (void *)(fd)-offsetof(struct s_file_slot, slot.fd);
|
slot = (void *)(fd)-offsetof(struct s_file_slot, slot.fd);
|
||||||
mem_set_zero(slot, sizeof(*slot));
|
mem_set_zero(slot, sizeof(*slot));
|
||||||
|
slot->ty = SLOT_UNUSED;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/30 16:26:32 by rparodi #+# #+# */
|
/* 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 ;
|
return ;
|
||||||
if (fclose(file->ptr) == -1)
|
if (fclose(file->ptr) == -1)
|
||||||
return ;
|
return ;
|
||||||
|
if (file->name != NULL)
|
||||||
|
mem_free(file->name);
|
||||||
slot = (void *)(file)-offsetof(struct s_file_slot, slot.file);
|
slot = (void *)(file)-offsetof(struct s_file_slot, slot.file);
|
||||||
mem_set_zero(slot, sizeof(*slot));
|
mem_set_zero(slot, sizeof(*slot));
|
||||||
|
slot->ty = SLOT_UNUSED;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/19 15:53:50 by maiboyer #+# #+# */
|
/* 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)
|
if (slot->ty == SLOT_UNUSED)
|
||||||
;
|
;
|
||||||
else if (slot->ty == SLOT_FD)
|
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)
|
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)
|
else if (slot->ty == SLOT_FILE)
|
||||||
(mem_free(slot->slot.file.name), close_file(&slot->slot.file));
|
close_file(&slot->slot.file);
|
||||||
else
|
else
|
||||||
(void)!write(2, "Unknown SLOT type", 17);
|
(void)!write(2, "Unknown SLOT type", 17);
|
||||||
mem_set_zero(slot, sizeof(*slot));
|
mem_set_zero(slot, sizeof(*slot));
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/07 13:08:52 by maiboyer #+# #+# */
|
/* 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)
|
void me_exit(t_i32 exit_code)
|
||||||
{
|
{
|
||||||
(get_stdin(), get_stdout(), get_stderr());
|
(get_stdin(), get_stdout(), get_stderr());
|
||||||
|
close_all_slots();
|
||||||
exit(exit_code);
|
exit(exit_code);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue