From be8da9daeb42c9c1be6b07a7fd1001cac2277ab8 Mon Sep 17 00:00:00 2001 From: Zxilly Date: Wed, 18 Dec 2024 19:34:06 +0800 Subject: [PATCH] fix: release args --- src/cache.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/cache.c b/src/cache.c index 49673fcb..c86106a8 100644 --- a/src/cache.c +++ b/src/cache.c @@ -22,24 +22,28 @@ typedef struct { } thread_args; _Noreturn static void* check_cache(void* arg) { - __auto_type args = (thread_args*)arg; + const __auto_type args = (thread_args *)arg; + const __auto_type lock = args->lock; + const __auto_type table = args->table; + const __auto_type check_interval = args->check_interval; + free(args); while (true) { - pthread_rwlock_wrlock(args->lock); + pthread_rwlock_wrlock(lock); const time_t now = time(NULL); struct cache *cur, *tmp; - HASH_ITER(hh, not_http_dst_cache, cur, tmp) { - if (difftime(now, cur->last_time) > args->check_interval) { + HASH_ITER(hh, table, cur, tmp) { + if (difftime(now, cur->last_time) > check_interval) { HASH_DEL(not_http_dst_cache, cur); free(cur); } } - pthread_rwlock_unlock(args->lock); + pthread_rwlock_unlock(lock); - sleep(args->check_interval); + sleep(check_interval); } }