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,28 +1,32 @@
|
|||
#include "ast_list.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
struct ast *ast_create_list(struct list *list)
|
||||
{
|
||||
struct ast_list *ast_list = malloc(sizeof(struct ast_list));
|
||||
if (ast_list == NULL)
|
||||
{
|
||||
perror("Error: could not allocate more memory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ast_list->children = list;
|
||||
|
||||
return ast_create(AST_LIST, ast_list);
|
||||
struct ast *result = ast_create(AST_LIST, ast_list);
|
||||
if (result == NULL)
|
||||
free(ast_list);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
struct ast_list *ast_get_list(struct ast *node)
|
||||
{
|
||||
if (node == NULL)
|
||||
if (node == NULL || node->type != AST_LIST)
|
||||
return NULL;
|
||||
return node->data;
|
||||
}
|
||||
|
||||
bool ast_is_list(struct ast *node)
|
||||
{
|
||||
return node != NULL && node->type == AST_LIST;
|
||||
}
|
||||
|
||||
void ast_free_list(struct ast_list *ast_list)
|
||||
{
|
||||
if (ast_list == NULL)
|
||||
|
|
@ -40,7 +44,7 @@ void ast_list_deep_destroy(struct list *l)
|
|||
{
|
||||
next_elt = elt->next;
|
||||
|
||||
struct ast *node = (struct ast *)elt->data;
|
||||
struct ast *node = elt->data;
|
||||
ast_free(&node);
|
||||
free(elt);
|
||||
elt = next_elt;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue