don't allocate char[PATH_MAX] for each file

This commit makes struct path allocation use strndup().
It reduices the memory footprint for struct path per file (issue #8).
This commit is contained in:
Ryo Nakamura
2024-01-11 21:23:33 +09:00
parent 5cbf3ad648
commit bba53fab03
3 changed files with 34 additions and 27 deletions

View File

@@ -714,7 +714,7 @@ out:
/* cleanup-related functions */
static void free_src(struct list_head *list)
static void list_free_src(struct list_head *list)
{
struct src *s;
s = list_entry(list, typeof(*s), list);
@@ -722,21 +722,14 @@ static void free_src(struct list_head *list)
free(s);
}
static void free_path(struct list_head *list)
static void list_free_path(struct list_head *list)
{
struct path *p;
p = list_entry(list, typeof(*p), list);
free(p);
free_path(p);
}
static void free_chunk(struct list_head *list)
{
struct chunk *c;
c = list_entry(list, typeof(*c), list);
free(c);
}
static void free_thread(struct list_head *list)
static void list_free_thread(struct list_head *list)
{
struct mscp_thread *t;
t = list_entry(list, typeof(*t), list);
@@ -750,17 +743,17 @@ void mscp_cleanup(struct mscp *m)
m->first = NULL;
}
list_free_f(&m->src_list, free_src);
list_free_f(&m->src_list, list_free_src);
INIT_LIST_HEAD(&m->src_list);
list_free_f(&m->path_list, free_path);
list_free_f(&m->path_list, list_free_path);
INIT_LIST_HEAD(&m->path_list);
chunk_pool_release(&m->cp);
chunk_pool_init(&m->cp);
RWLOCK_WRITE_ACQUIRE(&m->thread_rwlock);
list_free_f(&m->thread_list, free_thread);
list_free_f(&m->thread_list, list_free_thread);
RWLOCK_RELEASE();
}