From: zhang2639 Date: Thu, 24 May 2018 10:46:53 +0000 (+0800) Subject: Claim and use load_free() to free hash table. X-Git-Tag: lxcfs-3.1.0~24^2 X-Git-Url: https://git.proxmox.com/?p=mirror_lxcfs.git;a=commitdiff_plain;h=9c480eb7bc9e395fe150ba636837a94f0b75f723 Claim and use load_free() to free hash table. Signed-off-by: zhang2639 Signed-off-by: yuwang --- diff --git a/bindings.c b/bindings.c index b08cf43..b20eaa0 100644 --- a/bindings.c +++ b/bindings.c @@ -247,6 +247,38 @@ static struct load_node *del_node(struct load_node *n, int locate) return g; } +void load_free(void) +{ + int i; + struct load_node *f, *p; + + for (i = 0; i < LOAD_SIZE; i++) { + pthread_mutex_lock(&load_hash[i].lock); + pthread_rwlock_wrlock(&load_hash[i].rilock); + pthread_rwlock_wrlock(&load_hash[i].rdlock); + if (load_hash[i].next == NULL) { + pthread_mutex_unlock(&load_hash[i].lock); + pthread_mutex_destroy(&load_hash[i].lock); + pthread_rwlock_unlock(&load_hash[i].rilock); + pthread_rwlock_destroy(&load_hash[i].rilock); + pthread_rwlock_unlock(&load_hash[i].rdlock); + pthread_rwlock_destroy(&load_hash[i].rdlock); + continue; + } + for (f = load_hash[i].next; f; ) { + free(f->cg); + p = f->next; + free(f); + f = p; + } + pthread_mutex_unlock(&load_hash[i].lock); + pthread_mutex_destroy(&load_hash[i].lock); + pthread_rwlock_unlock(&load_hash[i].rilock); + pthread_rwlock_destroy(&load_hash[i].rilock); + pthread_rwlock_unlock(&load_hash[i].rdlock); + pthread_rwlock_destroy(&load_hash[i].rdlock); + } +} /* Reserve buffer size to account for file size changes. */ #define BUF_RESERVE_SIZE 512 diff --git a/bindings.h b/bindings.h index a34ac5f..6563011 100644 --- a/bindings.h +++ b/bindings.h @@ -33,5 +33,6 @@ extern int proc_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi); extern int proc_access(const char *path, int mask); extern pthread_t load_daemon(int load_use); +extern void load_free(void); #endif /* __LXCFS_BINDINGS_H */ diff --git a/lxcfs.c b/lxcfs.c index fe9c250..fe38148 100644 --- a/lxcfs.c +++ b/lxcfs.c @@ -937,6 +937,27 @@ int main(int argc, char *argv[]) } if (!fuse_main(nargs, newargv, &lxcfs_ops, NULL)) ret = EXIT_SUCCESS; + if (load_use == true) { + s = pthread_cancel(pid); + if (s == 0) { + s = pthread_join(pid, NULL); /* Make sure sub thread has been canceled. */ + if (s != 0) { + lxcfs_error("%s\n", "load_free error!"); + goto out; + } + dlerror(); /* Clear any existing error */ + + load_free = (void (*)(void)) dlsym(dlopen_handle, "load_free"); + error = dlerror(); + if (error != NULL) { + lxcfs_error("load_free error: %s\n", error); + goto out; + } + load_free(); + } else { + lxcfs_error("%s\n", "load_free error!"); + } + } out: if (dlopen_handle)