diff --git a/dfs.c b/dfs.c
index caca347f1717dc5e69dacc11a68b805b0270425c..6b977984d7fdfe71d306d4ea2b001d93c1bb8dcf 100644
--- a/dfs.c
+++ b/dfs.c
@@ -49,4 +49,15 @@ bool is_visited(char *path, struct list_head *visited)
 	}
 
 	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
diff --git a/dfs.h b/dfs.h
index 4666f5ea996397d239f7d9a4f4475c1048ab323d..ced31136ed76d5b48d6e48880a89a22e58fc9343 100644
--- a/dfs.h
+++ b/dfs.h
@@ -11,5 +11,6 @@ struct node {
 void enqueue_stack(struct node *n, struct list_head *stack);
 struct node *dequeue_stack(struct list_head *stack);
 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
\ No newline at end of file
diff --git a/dongle_infrastructure.c b/dongle_infrastructure.c
index e2eb86b26716e9d5c5dc83cf7794534ec65295ab..3f50e582f122a87ab46779b414ca75ca1d204640 100644
--- a/dongle_infrastructure.c
+++ b/dongle_infrastructure.c
@@ -289,6 +289,7 @@ char *dfs_get_path_name(char *folder_name)
 		}
 		closedir(dr);
 	}
+	clear_list(&visited);
 fail_opendir:
 	return NULL;
 success: