fix: fixed A LOT of bugs and memory leaks. Removed ast_is_* commands as they're not really useful and seems redundant with ast_get_*. Also made some changes to lists utils to make architecture clearer and some other random tweaks or fixes.
This commit is contained in:
parent
f31fca4204
commit
ac851fa895
31 changed files with 411 additions and 236 deletions
|
|
@ -1,38 +1,44 @@
|
|||
#include "ast_redir.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
bool ast_is_redir(struct ast *node)
|
||||
{
|
||||
return node != NULL && node->type == AST_REDIR;
|
||||
}
|
||||
|
||||
struct ast_redir *ast_get_redir(struct ast *node)
|
||||
{
|
||||
if (ast_is_redir(node))
|
||||
return (struct ast_redir *)node->data;
|
||||
return NULL;
|
||||
if (node == NULL || node->type != AST_REDIR)
|
||||
return NULL;
|
||||
return node->data;
|
||||
}
|
||||
|
||||
struct ast *ast_create_redir(char *filename, int io_number,
|
||||
enum ast_redir_type type)
|
||||
{
|
||||
struct ast_redir *redir = malloc(sizeof(struct ast_redir));
|
||||
if (!redir)
|
||||
struct ast_redir *redir_node = malloc(sizeof(struct ast_redir));
|
||||
if (redir_node == NULL)
|
||||
{
|
||||
perror("Error: could not allocate more memory");
|
||||
return NULL;
|
||||
redir->filename =
|
||||
}
|
||||
|
||||
redir_node->filename =
|
||||
filename; // Takes ownership? Usually yes in simple ASTs, or dup. Let's
|
||||
// assume pointer copy for now, but user must manage memory.
|
||||
redir->io_number = io_number;
|
||||
redir->type = type;
|
||||
redir_node->io_number = io_number;
|
||||
redir_node->type = type;
|
||||
|
||||
return ast_create(AST_REDIR, redir);
|
||||
struct ast *result = ast_create(AST_REDIR, redir_node);
|
||||
if (result == NULL)
|
||||
free(redir_node);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void ast_free_redir(struct ast_redir *redir)
|
||||
{
|
||||
if (!redir)
|
||||
if (redir == NULL)
|
||||
return;
|
||||
free(redir->filename);
|
||||
|
||||
if (redir->filename != NULL)
|
||||
free(redir->filename);
|
||||
free(redir);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue