fix: strdup a la con

This commit is contained in:
Gu://em_ 2026-01-30 21:27:23 +01:00
parent f721e6db72
commit b663655d53
2 changed files with 7 additions and 16 deletions

View file

@ -304,13 +304,12 @@ struct ast *parse_simple_command(struct lexer_context *ctx)
// Get element type
if (ast_is_word(element))
{
// Extract word
struct ast_word *element_word = ast_get_word(element);
// TODO test this fix for the memory leaks
char *word = strdup(element_word->word);
char *word = element_word->word;
element_word->word = NULL; // Prevents word to be freed
ast_free(&element);
command_elements = list_append(command_elements, word);
// end of fix
}
else if (ast_is_redir(element))
{
@ -344,20 +343,11 @@ struct ast *parse_element(struct lexer_context *ctx)
{
POP_TOKEN();
char *word = strdup(token->data);
if (word == NULL)
{
perror("Internal error: could not copy token data (is your memory "
"full ?)");
return NULL;
}
struct ast *result = ast_create_word(word);
struct ast *result = ast_create_word(token->data);
if (result == NULL)
{
perror("Internal error: could not create ast node (is your memory "
"full ?)");
free(word);
return NULL;
}