8 weeks ago
add resourcepools/common saf shutdown cleanup code
--- a/src/server/daemon/resourcepool.c Thu Jan 30 18:19:12 2025 +0100 +++ b/src/server/daemon/resourcepool.c Thu Jan 30 18:29:30 2025 +0100 @@ -43,6 +43,10 @@ return resource_pool_types ? 0 : 1; } +void resource_pool_cleanup(void) { + cxMapDestroy(resource_pool_types); +} + int resourcepool_register_type(const char *type_name, ResourceType *type_info) { if(cxMapPut(resource_pool_types, cx_hash_key_str(type_name), type_info)) { log_ereport(LOG_CATASTROPHE, "resourcepool_register_type: OOM");
--- a/src/server/daemon/resourcepool.h Thu Jan 30 18:19:12 2025 +0100 +++ b/src/server/daemon/resourcepool.h Thu Jan 30 18:29:30 2025 +0100 @@ -116,6 +116,8 @@ int init_resource_pools(void); +void resource_pool_cleanup(void); + int resourcepool_new(ServerConfiguration *cfg, cxstring type, cxstring name, ConfigNode *node); void resourcepool_destroy_resource(ResourceDataPrivate *res);
--- a/src/server/daemon/webserver.c Thu Jan 30 18:19:12 2025 +0100 +++ b/src/server/daemon/webserver.c Thu Jan 30 18:29:30 2025 +0100 @@ -290,11 +290,16 @@ // execute restart callbacks RestartCallback *re = atrestart; + RestartCallback *re_next; while(re) { re->func(re->data); - re = re->next; + re_next = re->next; + free(re); + re = re_next; } + resource_pool_cleanup(); + webserver_destroy(); }
--- a/src/server/safs/common.c Thu Jan 30 18:19:12 2025 +0100 +++ b/src/server/safs/common.c Thu Jan 30 18:29:30 2025 +0100 @@ -74,6 +74,10 @@ #define COMMONSAF_REQ_ABORTED -1 #define COMMONSAF_RET_ERROR -2 +static void common_saf_cleanup(void *d) { + cxMapDestroy(var_names); +} + void common_saf_init() { var_names = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 32); @@ -104,6 +108,8 @@ cxMapPut(var_names, cx_hash_key_str("http-upgrade"), (void*)(intptr_t)COMMONSAF_HTTP_UPGRADE); cxMapPut(var_names, cx_hash_key_str("keep-alive"), (void*)(intptr_t)COMMONSAF_KEEP_ALIVE); cxMapPut(var_names, cx_hash_key_str("name"), (void*)(intptr_t)COMMONSAF_NAME); + + webserver_atrestart(common_saf_cleanup, NULL); } int print_message(pblock *pb, Session *sn, Request *rq) {