Skip to content
Snippets Groups Projects
Commit 2fa2fdd8 authored by Jakob Olsson's avatar Jakob Olsson
Browse files

add clear_list function

parent ddebdbb1
Branches
No related tags found
No related merge requests found
...@@ -49,4 +49,15 @@ bool is_visited(char *path, struct list_head *visited) ...@@ -49,4 +49,15 @@ bool is_visited(char *path, struct list_head *visited)
} }
return false; return false;
}
void clear_list(struct list_head *visited)
{
struct node *n, *tmp;
list_for_each_entry_safe(n, tmp, visited, list) {
free(n->path);
list_del(n->list);
free(n);
}
} }
\ No newline at end of file
...@@ -11,5 +11,6 @@ struct node { ...@@ -11,5 +11,6 @@ struct node {
void enqueue_stack(struct node *n, struct list_head *stack); void enqueue_stack(struct node *n, struct list_head *stack);
struct node *dequeue_stack(struct list_head *stack); struct node *dequeue_stack(struct list_head *stack);
void add_visited(struct node *n, struct list_head *visited); void add_visited(struct node *n, struct list_head *visited);
bool is_visited(struct node *n, struct list_head *visited); bool is_visited(char *path, struct list_head *visited);
void clear_list(struct list_head *visited);
#endif #endif
\ No newline at end of file
...@@ -289,6 +289,7 @@ char *dfs_get_path_name(char *folder_name) ...@@ -289,6 +289,7 @@ char *dfs_get_path_name(char *folder_name)
} }
closedir(dr); closedir(dr);
} }
clear_list(&visited);
fail_opendir: fail_opendir:
return NULL; return NULL;
success: success:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment