REORG: server: add a free server function
Create a new server function named free_server. It can be used to
deallocate a server and its member.
diff --git a/include/haproxy/server.h b/include/haproxy/server.h
index 0bcae85..518c20a 100644
--- a/include/haproxy/server.h
+++ b/include/haproxy/server.h
@@ -59,6 +59,7 @@
int srv_init_addr(void);
struct server *cli_find_server(struct appctx *appctx, char *arg);
struct server *new_server(struct proxy *proxy);
+void free_server(struct server *srv);
/* functions related to server name resolution */
int srv_prepare_for_resolution(struct server *srv, const char *hostname);
diff --git a/src/haproxy.c b/src/haproxy.c
index 3efbac0..433d1b8 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -2660,31 +2660,10 @@
while (s) {
s_next = s->next;
-
- task_destroy(s->warmup);
-
- free(s->id);
- free(s->cookie);
- free(s->hostname);
- free(s->hostname_dn);
- free((char*)s->conf.file);
- free(s->per_thr);
- free(s->curr_idle_thr);
- free(s->resolvers_id);
- free(s->addr_node.key);
-
- if (s->use_ssl == 1 || s->check.use_ssl == 1 || (s->proxy->options & PR_O_TCPCHK_SSL)) {
- if (xprt_get(XPRT_SSL) && xprt_get(XPRT_SSL)->destroy_srv)
- xprt_get(XPRT_SSL)->destroy_srv(s);
- }
- HA_SPIN_DESTROY(&s->lock);
-
list_for_each_entry(srvdf, &server_deinit_list, list)
srvdf->fct(s);
- EXTRA_COUNTERS_FREE(s->extra_counters);
- LIST_DEL(&s->global_list);
- free(s);
+ free_server(s);
s = s_next;
}/* end while(s) */
diff --git a/src/server.c b/src/server.c
index 8935a6a..7c08dd0 100644
--- a/src/server.c
+++ b/src/server.c
@@ -1840,6 +1840,36 @@
return srv;
}
+/* Deallocate a server <srv> and its member. <srv> must be allocated.
+ */
+void free_server(struct server *srv)
+{
+ task_destroy(srv->warmup);
+
+ free(srv->id);
+ free(srv->cookie);
+ free(srv->hostname);
+ free(srv->hostname_dn);
+ free((char*)srv->conf.file);
+ free(srv->per_thr);
+ free(srv->curr_idle_thr);
+ free(srv->resolvers_id);
+ free(srv->addr_node.key);
+
+ if (srv->use_ssl == 1 || srv->check.use_ssl == 1 || (srv->proxy->options & PR_O_TCPCHK_SSL)) {
+ if (xprt_get(XPRT_SSL) && xprt_get(XPRT_SSL)->destroy_srv)
+ xprt_get(XPRT_SSL)->destroy_srv(srv);
+ }
+ HA_SPIN_DESTROY(&srv->lock);
+
+ LIST_DEL(&srv->global_list);
+
+ EXTRA_COUNTERS_FREE(srv->extra_counters);
+
+ free(srv);
+ srv = NULL;
+}
+
#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
static int server_sni_expr_init(const char *file, int linenum, char **args, int cur_arg,
struct server *srv, struct proxy *proxy)