]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: memory: use pool_destroy_all() to destroy all pools on deinit()
authorWilly Tarreau <w@1wt.eu>
Mon, 26 Nov 2018 14:57:34 +0000 (15:57 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 26 Nov 2018 18:50:32 +0000 (19:50 +0100)
Instead of exporting a number of pools and having to manually delete
them in deinit() or to have dedicated destructors to remove them, let's
simply kill all pools on deinit().

For this a new function pool_destroy_all() was introduced. As its name
implies, it destroys and frees all pools (provided they don't have any
user anymore of course).

This allowed to remove 4 implicit destructors, 2 explicit ones, and 11
individual calls to pool_destroy(). In addition it properly removes
the mux_pt_ctx pool which was not cleared on exit (no backport needed
here since it's 1.9 only). The sig_handler pool doesn't need to be
exported anymore and became static now.

14 files changed:
include/common/buffer.h
include/common/chunk.h
include/common/memory.h
include/proto/signal.h
src/buffer.c
src/chunk.c
src/dns.c
src/filters.c
src/flt_spoe.c
src/haproxy.c
src/memory.c
src/mux_h1.c
src/mux_h2.c
src/signal.c

index 1c7963fd4c91862334417aa4331b0d934cfce968..ac480566da741fe57c2b1bedadcdab572fca1b0f 100644 (file)
@@ -47,7 +47,6 @@ extern struct list buffer_wq;
 __decl_hathreads(extern HA_SPINLOCK_T buffer_wq_lock);
 
 int init_buffer();
-void deinit_buffer();
 void buffer_dump(FILE *o, struct buffer *b, int from, int to);
 
 /*****************************************************************/
index ffcb93c8ff50003d9c5471c01da4a03efc19760d..ebd194a2d3cf6a7b8bc5f5e67e4d43c34b4e867d 100644 (file)
@@ -47,7 +47,6 @@ int chunk_strcasecmp(const struct buffer *chk, const char *str);
 struct buffer *get_trash_chunk(void);
 struct buffer *alloc_trash_chunk(void);
 int init_trash_buffers(int first);
-void deinit_trash_buffers(void);
 
 /*
  * free a trash chunk allocated by alloc_trash_chunk(). NOP on NULL.
index 5bed60294359b5ed843aa900952d4a58cc787894..f0f6e1381051327a87f3c625e263ba6ded373fa5 100644 (file)
@@ -161,6 +161,7 @@ void pool_gc(struct pool_head *pool_ctx);
  * This should be called only under extreme circumstances.
  */
 void *pool_destroy(struct pool_head *pool);
+void pool_destroy_all();
 
 /* returns the pool index for pool <pool>, or -1 if this pool has no index */
 static inline ssize_t pool_get_index(const struct pool_head *pool)
index 0806d04225871ac6ca1afc94b2f08916f47298f5..ff6976d35c27677e84d4953b317be65bf7d4de69 100644 (file)
@@ -20,7 +20,6 @@
 
 extern int signal_queue_len;
 extern struct signal_descriptor signal_state[];
-extern struct pool_head *pool_head_sig_handlers;
 
 __decl_hathreads(extern HA_SPINLOCK_T signals_lock);
 
index e55c5bdd2a4b23a21915f6de79742213af7d801a..c4d61405135f690484b497a8b25b14b8d6d7bf8a 100644 (file)
@@ -54,11 +54,6 @@ int init_buffer()
        return 1;
 }
 
-void deinit_buffer()
-{
-       pool_destroy(pool_head_buffer);
-}
-
 /*
  * Dumps part or all of a buffer.
  */
index fa3fb71dfa2953c589b43245330b6fad4a80dac8..e052322bc54f9067e2b6878b8e59ec626a3a19d9 100644 (file)
@@ -101,14 +101,6 @@ int init_trash_buffers(int first)
        return 1;
 }
 
-/*
- * free the trash buffers
- */
-void deinit_trash_buffers(void)
-{
-       pool_destroy(pool_head_trash);
-}
-
 /*
  * Allocate a trash chunk from the reentrant pool. The buffer starts at the
  * end of the chunk. This chunk must be freed using free_trash_chunk(). This
index 10ccf873fbc6e72aa076b29c12efef8fe60da161..2a53c038c377d394371f7f7b535c2a0b236232c4 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
@@ -1839,9 +1839,6 @@ static void dns_deinit(void)
                LIST_DEL(&srvrq->list);
                free(srvrq);
        }
-
-       pool_destroy(dns_answer_item_pool);
-       pool_destroy(dns_resolution_pool);
 }
 
 /* Finalizes the DNS configuration by allocating required resources and checking
index 7b5700d497bad34d861b30f93fa95f231737f7e5..d29a0c08e8e9de26df6c734b1c4100d3e9a98194 100644 (file)
@@ -1192,13 +1192,6 @@ static struct cfg_kw_list cfg_kws = {ILH, {
 
 INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws);
 
-__attribute__((destructor))
-static void
-__filters_deinit(void)
-{
-       pool_destroy(pool_head_filter);
-}
-
 REGISTER_POST_CHECK(flt_init_all);
 REGISTER_PER_THREAD_INIT(flt_init_all_per_thread);
 REGISTER_PER_THREAD_DEINIT(flt_deinit_all_per_thread);
index 8d630815b2a267739493b6f3a65ca56abede1d9d..bd351be18059935e3a8f240fdcc9a7f7b47d9091 100644 (file)
@@ -4676,11 +4676,3 @@ static struct action_kw_list http_res_action_kws = { { }, {
 };
 
 INITCALL1(STG_REGISTER, http_res_keywords_register, &http_res_action_kws);
-
-__attribute__((destructor))
-static void
-__spoe_deinit(void)
-{
-       pool_destroy(pool_head_spoe_ctx);
-       pool_destroy(pool_head_spoe_appctx);
-}
index 6ec9bcc846bf7fc80aaaf0f9dc164397988f438c..96715ee274e0cb16d34eaf1e79fdc751ad0c75d4 100644 (file)
@@ -2500,7 +2500,6 @@ void deinit(void)
        cfg_unregister_sections();
 
        deinit_log_buffers();
-       deinit_trash_buffers();
 
        protocol_unbind_all();
 
@@ -2534,20 +2533,7 @@ void deinit(void)
        }
 
        vars_prune(&global.vars, NULL, NULL);
-
-       deinit_buffer();
-
-       pool_destroy(pool_head_stream);
-       pool_destroy(pool_head_session);
-       pool_destroy(pool_head_connection);
-       pool_destroy(pool_head_connstream);
-       pool_destroy(pool_head_requri);
-       pool_destroy(pool_head_task);
-       pool_destroy(pool_head_capture);
-       pool_destroy(pool_head_pendconn);
-       pool_destroy(pool_head_sig_handlers);
-       pool_destroy(pool_head_hdr_idx);
-       pool_destroy(pool_head_http_txn);
+       pool_destroy_all();
        deinit_pollers();
 } /* end deinit() */
 
index 587702a2ea3a22fbb3c765f4e538d3af5cdc5344..6d2eacd61e9aed7a80d1fe03f4e8109ede91879f 100644 (file)
@@ -436,6 +436,15 @@ void *pool_destroy(struct pool_head *pool)
        return NULL;
 }
 
+/* This destroys all pools on exit. It is *not* thread safe. */
+void pool_destroy_all()
+{
+       struct pool_head *entry, *back;
+
+       list_for_each_entry_safe(entry, back, &pools, list)
+               pool_destroy(entry);
+}
+
 /* This function dumps memory usage information into the trash buffer. */
 void dump_pools_to_trash()
 {
index a845a24165eabdd8269ed43b1067724241428246..bade571a7d035e5bdbe4a88c07ad97df980dd738 100644 (file)
@@ -1826,14 +1826,6 @@ static struct mux_proto_list mux_proto_htx =
 
 INITCALL1(STG_REGISTER, register_mux_proto, &mux_proto_htx);
 
-static void __h1_deinit(void)
-{
-       pool_destroy(pool_head_h1c);
-       pool_destroy(pool_head_h1s);
-}
-
-REGISTER_POST_DEINIT(__h1_deinit);
-
 /*
  * Local variables:
  *  c-indent-level: 8
index a30de3d047081a8543cf8c12a3864e544ec358ff..197179221de0e198a24331da239e4e0a482907d6 100644 (file)
@@ -3845,11 +3845,3 @@ static struct cfg_kw_list cfg_kws = {ILH, {
 }};
 
 INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws);
-
-static void __h2_deinit(void)
-{
-       pool_destroy(pool_head_h2s);
-       pool_destroy(pool_head_h2c);
-}
-
-REGISTER_POST_DEINIT(__h2_deinit);
index 4ee55024f736bc86599a84baba9195dd9df2bd1c..b6ed1a60e0c61296f4cf0b3aaf4844f66007a871 100644 (file)
@@ -32,7 +32,7 @@ struct signal_descriptor signal_state[MAX_SIGNAL];
 sigset_t blocked_sig;
 int signal_pending = 0; /* non-zero if t least one signal remains unprocessed */
 
-DECLARE_POOL(pool_head_sig_handlers, "sig_handlers", sizeof(struct sig_handler));
+DECLARE_STATIC_POOL(pool_head_sig_handlers, "sig_handlers", sizeof(struct sig_handler));
 
 /* Common signal handler, used by all signals. Received signals are queued.
  * Signal number zero has a specific status, as it cannot be delivered by the