From b73949e03f72349b2ce90276d275487044e26c67 Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Tue, 19 Nov 2019 03:39:40 -0500 Subject: [PATCH] [multiple] plugin.c handles common FREE_FUNC code (simpler for modules; less boilerplate to cut-n-paste) --- src/gw_backend.c | 9 ++------- src/gw_backend.h | 2 +- src/mod_access.c | 12 ------------ src/mod_accesslog.c | 18 +++--------------- src/mod_alias.c | 12 ------------ src/mod_auth.c | 15 ++------------- src/mod_authn_file.c | 11 ----------- src/mod_authn_gssapi.c | 11 ----------- src/mod_authn_ldap.c | 14 ++------------ src/mod_authn_mysql.c | 17 +++-------------- src/mod_authn_pam.c | 11 ----------- src/mod_authn_sasl.c | 18 +++--------------- src/mod_cgi.c | 10 ---------- src/mod_cml.c | 23 +++++------------------ src/mod_compress.c | 8 -------- src/mod_deflate.c | 8 -------- src/mod_dirlisting.c | 19 +++---------------- src/mod_evasive.c | 12 ------------ src/mod_evhost.c | 21 ++++----------------- src/mod_expire.c | 12 ------------ src/mod_extforward.c | 18 +++--------------- src/mod_flv_streaming.c | 12 ------------ src/mod_geoip.c | 16 ++-------------- src/mod_indexfile.c | 12 ------------ src/mod_magnet.c | 8 -------- src/mod_maxminddb.c | 18 ++---------------- src/mod_mysql_vhost.c | 28 ++++------------------------ src/mod_openssl.c | 13 ++++--------- src/mod_proxy.c | 7 ++----- src/mod_redirect.c | 16 ++-------------- src/mod_rewrite.c | 16 ++-------------- src/mod_rrdtool.c | 13 ++++--------- src/mod_secdownload.c | 12 ------------ src/mod_setenv.c | 12 ------------ src/mod_simple_vhost.c | 8 -------- src/mod_skeleton.c | 13 ------------- src/mod_ssi.c | 9 --------- src/mod_staticfile.c | 12 ------------ src/mod_status.c | 12 ------------ src/mod_trigger_b4_dl.c | 16 ++-------------- src/mod_uploadprogress.c | 8 -------- src/mod_userdir.c | 12 ------------ src/mod_usertrack.c | 12 ------------ src/mod_vhostdb.c | 8 -------- src/mod_vhostdb_dbi.c | 16 ++-------------- src/mod_vhostdb_ldap.c | 16 ++-------------- src/mod_vhostdb_mysql.c | 16 ++-------------- src/mod_vhostdb_pgsql.c | 16 ++-------------- src/mod_webdav.c | 16 ++-------------- src/plugin.c | 25 ++++++++++++++++++------- src/plugin.h | 10 +++++----- 51 files changed, 88 insertions(+), 601 deletions(-) diff --git a/src/gw_backend.c b/src/gw_backend.c index a79288ed..4e41e8a7 100644 --- a/src/gw_backend.c +++ b/src/gw_backend.c @@ -1156,11 +1156,9 @@ void gw_plugin_config_free(gw_plugin_config *s) { free(s); } -handler_t gw_free(server *srv, void *p_d) { +void gw_free(void *p_d) { gw_plugin_data * const p = p_d; - if (!p) return HANDLER_GO_ON; - UNUSED(srv); - if (NULL == p->cvlist) { free(p); return HANDLER_GO_ON; } + if (NULL == p->cvlist) return; /* (init i to 0 if global context; to 1 to skip empty global context) */ for (int i = !p->cvlist[0].v.u2[1], used = p->nconfig; i < used; ++i) { config_plugin_value_t *cpv = p->cvlist + p->cvlist[i].v.u2[0]; @@ -1175,9 +1173,6 @@ handler_t gw_free(server *srv, void *p_d) { } } } - free(p->cvlist); - free(p); - return HANDLER_GO_ON; } int gw_set_defaults_backend(server *srv, gw_plugin_data *p, const array *a, gw_plugin_config *s, int sh_exec, const char *cpkkey) { diff --git a/src/gw_backend.h b/src/gw_backend.h index cb17b236..2d030561 100644 --- a/src/gw_backend.h +++ b/src/gw_backend.h @@ -334,7 +334,7 @@ __attribute_cold__ void gw_plugin_config_free(gw_plugin_config *s); __attribute_cold__ -handler_t gw_free(server *srv, void *p_d); +void gw_free(void *p_d); __attribute_cold__ int gw_set_defaults_backend(server *srv, gw_plugin_data *p, const array *a, gw_plugin_config *s, int sh_exec, const char *cpkkey); diff --git a/src/mod_access.c b/src/mod_access.c index 4281e3c1..11263b97 100644 --- a/src/mod_access.c +++ b/src/mod_access.c @@ -25,17 +25,6 @@ INIT_FUNC(mod_access_init) { return calloc(1, sizeof(plugin_data)); } -FREE_FUNC(mod_access_free) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - UNUSED(srv); - - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; -} - static void mod_access_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { switch (cpv->k_id) { /* index into static config_plugin_keys_t cpk[] */ case 0: /* url.access-deny */ @@ -189,7 +178,6 @@ int mod_access_plugin_init(plugin *p) { p->set_defaults = mod_access_set_defaults; p->handle_uri_clean = mod_access_uri_handler; p->handle_subrequest_start = mod_access_uri_handler; - p->cleanup = mod_access_free; return 0; } diff --git a/src/mod_accesslog.c b/src/mod_accesslog.c index d59fb217..1b2fdb09 100644 --- a/src/mod_accesslog.c +++ b/src/mod_accesslog.c @@ -451,7 +451,9 @@ static void mod_accesslog_free_format_fields(format_fields * const ff) { free(ff); } -static void mod_accesslog_free_config(plugin_data * const p) { +FREE_FUNC(mod_accesslog_free) { + plugin_data * const p = p_d; + free(p->syslog_logbuffer.ptr); if (NULL == p->cvlist) return; /* (init i to 0 if global context; to 1 to skip empty global context) */ for (int i = !p->cvlist[0].v.u2[1], used = p->nconfig; i < used; ++i) { @@ -476,20 +478,6 @@ static void mod_accesslog_free_config(plugin_data * const p) { } } -FREE_FUNC(mod_accesslog_free) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - UNUSED(srv); - - mod_accesslog_free_config(p); - - free(p->syslog_logbuffer.ptr); - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; -} - static void mod_accesslog_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { switch (cpv->k_id) { /* index into static config_plugin_keys_t cpk[] */ case 0:{/* accesslog.filename */ diff --git a/src/mod_alias.c b/src/mod_alias.c index 3862ee79..21d982f6 100644 --- a/src/mod_alias.c +++ b/src/mod_alias.c @@ -24,17 +24,6 @@ INIT_FUNC(mod_alias_init) { return calloc(1, sizeof(plugin_data)); } -FREE_FUNC(mod_alias_free) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - UNUSED(srv); - - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; -} - static void mod_alias_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { switch (cpv->k_id) { /* index into static config_plugin_keys_t cpk[] */ case 0: /* alias.url */ @@ -192,7 +181,6 @@ int mod_alias_plugin_init(plugin *p) { p->init = mod_alias_init; p->handle_physical= mod_alias_physical_handler; p->set_defaults = mod_alias_set_defaults; - p->cleanup = mod_alias_free; return 0; } diff --git a/src/mod_auth.c b/src/mod_auth.c index b1490a5a..618a55ca 100644 --- a/src/mod_auth.c +++ b/src/mod_auth.c @@ -50,7 +50,8 @@ INIT_FUNC(mod_auth_init) { return p; } -static void mod_auth_free_config(plugin_data * const p) { +FREE_FUNC(mod_auth_free) { + plugin_data * const p = p_d; if (NULL == p->cvlist) return; /* (init i to 0 if global context; to 1 to skip empty global context) */ for (int i = !p->cvlist[0].v.u2[1], used = p->nconfig; i < used; ++i) { @@ -68,18 +69,6 @@ static void mod_auth_free_config(plugin_data * const p) { } } -FREE_FUNC(mod_auth_free) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - - mod_auth_free_config(p); - - free(p->cvlist); - free(p); - UNUSED(srv); - return HANDLER_GO_ON; -} - /* data type for mod_auth structured data * (parsed from auth.require array of strings) */ typedef struct { diff --git a/src/mod_authn_file.c b/src/mod_authn_file.c index d7c149a2..02922595 100644 --- a/src/mod_authn_file.c +++ b/src/mod_authn_file.c @@ -89,16 +89,6 @@ INIT_FUNC(mod_authn_file_init) { return p; } -FREE_FUNC(mod_authn_file_free) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - - free(p->cvlist); - free(p); - UNUSED(srv); - return HANDLER_GO_ON; -} - static void mod_authn_file_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { switch (cpv->k_id) { /* index into static config_plugin_keys_t cpk[] */ case 0: /* auth.backend.plain.groupfile */ @@ -743,7 +733,6 @@ int mod_authn_file_plugin_init(plugin *p) { p->name = "authn_file"; p->init = mod_authn_file_init; p->set_defaults= mod_authn_file_set_defaults; - p->cleanup = mod_authn_file_free; return 0; } diff --git a/src/mod_authn_gssapi.c b/src/mod_authn_gssapi.c index bc8f6d81..6ce112d2 100644 --- a/src/mod_authn_gssapi.c +++ b/src/mod_authn_gssapi.c @@ -68,16 +68,6 @@ INIT_FUNC(mod_authn_gssapi_init) { return p; } -FREE_FUNC(mod_authn_gssapi_free) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - - free(p->cvlist); - free(p); - UNUSED(srv); - return HANDLER_GO_ON; -} - static void mod_authn_gssapi_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { switch (cpv->k_id) { /* index into static config_plugin_keys_t cpk[] */ case 0: /* auth.backend.gssapi.keytab */ @@ -791,7 +781,6 @@ int mod_authn_gssapi_plugin_init(plugin *p) { p->name = "authn_gssapi"; p->init = mod_authn_gssapi_init; p->set_defaults= mod_authn_gssapi_set_defaults; - p->cleanup = mod_authn_gssapi_free; p->connection_reset = mod_authn_gssapi_handle_reset; return 0; diff --git a/src/mod_authn_ldap.c b/src/mod_authn_ldap.c index 0c7699e6..cd92fb7d 100644 --- a/src/mod_authn_ldap.c +++ b/src/mod_authn_ldap.c @@ -56,7 +56,8 @@ INIT_FUNC(mod_authn_ldap_init) { return p; } -static void mod_authn_ldap_free_config(plugin_data *p) { +FREE_FUNC(mod_authn_ldap_free) { + plugin_data * const p = p_d; if (NULL == p->cvlist) return; /* (init i to 0 if global context; to 1 to skip empty global context) */ for (int i = !p->cvlist[0].v.u2[1], used = p->nconfig; i < used; ++i) { @@ -75,19 +76,8 @@ static void mod_authn_ldap_free_config(plugin_data *p) { } } } -} -FREE_FUNC(mod_authn_ldap_free) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - - mod_authn_ldap_free_config(p); free(p->ldap_filter.ptr); - - free(p->cvlist); - free(p); - UNUSED(srv); - return HANDLER_GO_ON; } static void mod_authn_ldap_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { diff --git a/src/mod_authn_mysql.c b/src/mod_authn_mysql.c index 1195aad8..14e53bc3 100644 --- a/src/mod_authn_mysql.c +++ b/src/mod_authn_mysql.c @@ -64,7 +64,8 @@ typedef struct { int mysql_conn_port; } plugin_data; -static void mod_authn_mysql_sock_close(plugin_data *p) { +static void mod_authn_mysql_sock_close(void *p_d) { + plugin_data * const p = p_d; if (NULL != p->mysql_conn) { mysql_close(p->mysql_conn); p->mysql_conn = NULL; @@ -155,18 +156,6 @@ INIT_FUNC(mod_authn_mysql_init) { return p; } -FREE_FUNC(mod_authn_mysql_free) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - - mod_authn_mysql_sock_close(p); - - free(p->cvlist); - free(p); - UNUSED(srv); - return HANDLER_GO_ON; -} - static void mod_authn_mysql_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { switch (cpv->k_id) { /* index into static config_plugin_keys_t cpk[] */ case 0: /* auth.backend.mysql.host */ @@ -522,7 +511,7 @@ int mod_authn_mysql_plugin_init(plugin *p) { p->name = "authn_mysql"; p->init = mod_authn_mysql_init; p->set_defaults= mod_authn_mysql_set_defaults; - p->cleanup = mod_authn_mysql_free; + p->cleanup = mod_authn_mysql_sock_close; return 0; } diff --git a/src/mod_authn_pam.c b/src/mod_authn_pam.c index 61925e80..6ffb725b 100644 --- a/src/mod_authn_pam.c +++ b/src/mod_authn_pam.c @@ -45,16 +45,6 @@ INIT_FUNC(mod_authn_pam_init) { return p; } -FREE_FUNC(mod_authn_pam_free) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - - free(p->cvlist); - free(p); - UNUSED(srv); - return HANDLER_GO_ON; -} - static void mod_authn_pam_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { switch (cpv->k_id) { /* index into static config_plugin_keys_t cpk[] */ case 0: /* auth.backend.pam.opts */ @@ -177,7 +167,6 @@ int mod_authn_pam_plugin_init(plugin *p) { p->version = LIGHTTPD_VERSION_ID; p->name = "authn_pam"; p->init = mod_authn_pam_init; - p->cleanup = mod_authn_pam_free; p->set_defaults= mod_authn_pam_set_defaults; return 0; diff --git a/src/mod_authn_sasl.c b/src/mod_authn_sasl.c index deafde30..4ced62c7 100644 --- a/src/mod_authn_sasl.c +++ b/src/mod_authn_sasl.c @@ -51,7 +51,9 @@ INIT_FUNC(mod_authn_sasl_init) { return p; } -static void mod_authn_sasl_free_config(plugin_data * const p) { +FREE_FUNC(mod_authn_sasl_free) { + plugin_data * const p = p_d; + if (p->initonce) sasl_done(); if (NULL == p->cvlist) return; /* (init i to 0 if global context; to 1 to skip empty global context) */ for (int i = !p->cvlist[0].v.u2[1], used = p->nconfig; i < used; ++i) { @@ -68,20 +70,6 @@ static void mod_authn_sasl_free_config(plugin_data * const p) { } } -FREE_FUNC(mod_authn_sasl_free) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - - if (p->initonce) sasl_done(); - - mod_authn_sasl_free_config(p); - - free(p->cvlist); - free(p); - UNUSED(srv); - return HANDLER_GO_ON; -} - static void mod_authn_sasl_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { switch (cpv->k_id) { /* index into static config_plugin_keys_t cpk[] */ case 0: /* auth.backend.sasl.opts */ diff --git a/src/mod_cgi.c b/src/mod_cgi.c index 72f0e789..2474e740 100644 --- a/src/mod_cgi.c +++ b/src/mod_cgi.c @@ -135,12 +135,7 @@ INIT_FUNC(mod_cgi_init) { FREE_FUNC(mod_cgi_free) { plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - buffer_pid_t *r = &(p->cgi_pid); - - UNUSED(srv); - if (r->ptr) free(r->ptr); free(p->env.ptr); free(p->env.offsets); @@ -150,11 +145,6 @@ FREE_FUNC(mod_cgi_free) { #ifdef __CYGWIN__ buffer_free(p->env.systemroot); #endif - - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; } static void mod_cgi_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { diff --git a/src/mod_cml.c b/src/mod_cml.c index 2d620d66..314c4036 100644 --- a/src/mod_cml.c +++ b/src/mod_cml.c @@ -18,7 +18,11 @@ INIT_FUNC(mod_cml_init) { return calloc(1, sizeof(plugin_data)); } -static void mod_cml_free_config(plugin_data * const p) { +FREE_FUNC(mod_cml_free) { + plugin_data * const p = p_d; + free(p->trigger_handler.ptr); + free(p->basedir.ptr); + free(p->baseurl.ptr); if (NULL == p->cvlist) return; #if defined(USE_MEMCACHED) /* (init i to 0 if global context; to 1 to skip empty global context) */ @@ -77,23 +81,6 @@ static int mod_cml_init_memcached(server *srv, config_plugin_value_t * const cpv #endif } -FREE_FUNC(mod_cml_free) { - plugin_data * const p = p_d; - if (!p) return HANDLER_GO_ON; - UNUSED(srv); - - free(p->trigger_handler.ptr); - free(p->basedir.ptr); - free(p->baseurl.ptr); - - mod_cml_free_config(p); - - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; -} - static void mod_cml_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { switch (cpv->k_id) { /* index into static config_plugin_keys_t cpk[] */ case 0: /* cml.extension */ diff --git a/src/mod_compress.c b/src/mod_compress.c index 15087653..4aa62351 100644 --- a/src/mod_compress.c +++ b/src/mod_compress.c @@ -91,16 +91,8 @@ INIT_FUNC(mod_compress_init) { FREE_FUNC(mod_compress_free) { plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - UNUSED(srv); - buffer_free(p->ofn); buffer_free(p->b); - - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; } /* 0 on success, -1 for error */ diff --git a/src/mod_deflate.c b/src/mod_deflate.c index bddda989..ea465ca1 100644 --- a/src/mod_deflate.c +++ b/src/mod_deflate.c @@ -233,15 +233,7 @@ INIT_FUNC(mod_deflate_init) { FREE_FUNC(mod_deflate_free) { plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - UNUSED(srv); - free(p->tmp_buf.ptr); - - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; } static void mod_deflate_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { diff --git a/src/mod_dirlisting.c b/src/mod_dirlisting.c index af1b9a78..1cd0d351 100644 --- a/src/mod_dirlisting.c +++ b/src/mod_dirlisting.c @@ -116,7 +116,9 @@ INIT_FUNC(mod_dirlisting_init) { return calloc(1, sizeof(plugin_data)); } -static void mod_dirlisting_free_config(plugin_data * const p) { +FREE_FUNC(mod_dirlisting_free) { + plugin_data * const p = p_d; + free(p->tmp_buf.ptr); if (NULL == p->cvlist) return; /* (init i to 0 if global context; to 1 to skip empty global context) */ for (int i = !p->cvlist[0].v.u2[1], used = p->nconfig; i < used; ++i) { @@ -138,21 +140,6 @@ static void mod_dirlisting_free_config(plugin_data * const p) { } } -FREE_FUNC(mod_dirlisting_free) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - UNUSED(srv); - - mod_dirlisting_free_config(p); - free(p->tmp_buf.ptr); - - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; -} - - static void mod_dirlisting_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { switch (cpv->k_id) { /* index into static config_plugin_keys_t cpk[] */ case 0: /* dir-listing.activate */ diff --git a/src/mod_evasive.c b/src/mod_evasive.c index 1c1b0687..40c9e492 100644 --- a/src/mod_evasive.c +++ b/src/mod_evasive.c @@ -42,17 +42,6 @@ INIT_FUNC(mod_evasive_init) { return calloc(1, sizeof(plugin_data)); } -FREE_FUNC(mod_evasive_free) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - UNUSED(srv); - - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; -} - static void mod_evasive_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { switch (cpv->k_id) { /* index into static config_plugin_keys_t cpk[] */ case 0: /* evasive.max-conns-per-ip */ @@ -163,7 +152,6 @@ int mod_evasive_plugin_init(plugin *p) { p->init = mod_evasive_init; p->set_defaults = mod_evasive_set_defaults; p->handle_uri_clean = mod_evasive_uri_handler; - p->cleanup = mod_evasive_free; return 0; } diff --git a/src/mod_evhost.c b/src/mod_evhost.c index ae438430..3bc143b4 100644 --- a/src/mod_evhost.c +++ b/src/mod_evhost.c @@ -50,7 +50,10 @@ static void mod_evhost_free_path_pieces(const buffer *path_pieces) { free(b); } -static void mod_evhost_free_config(plugin_data * const p) { +FREE_FUNC(mod_evhost_free) { + plugin_data * const p = p_d; + free(p->tmp_buf.ptr); + array_free_data(&p->split_vals); if (NULL == p->cvlist) return; /* (init i to 0 if global context; to 1 to skip empty global context) */ for (int i = !p->cvlist[0].v.u2[1], used = p->nconfig; i < used; ++i) { @@ -68,22 +71,6 @@ static void mod_evhost_free_config(plugin_data * const p) { } } -FREE_FUNC(mod_evhost_free) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - UNUSED(srv); - - mod_evhost_free_config(p); - - free(p->tmp_buf.ptr); - array_free_data(&p->split_vals); - - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; -} - __attribute_cold__ static buffer * mod_evhost_parse_pattern_err(buffer *bptr) { for (; bptr->ptr; ++bptr) free(bptr->ptr); diff --git a/src/mod_expire.c b/src/mod_expire.c index 4bc34c45..d722d0d7 100644 --- a/src/mod_expire.c +++ b/src/mod_expire.c @@ -32,17 +32,6 @@ INIT_FUNC(mod_expire_init) { return calloc(1, sizeof(plugin_data)); } -FREE_FUNC(mod_expire_free) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - UNUSED(srv); - - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; -} - static int mod_expire_get_offset(server *srv, plugin_data *p, const buffer *expire, time_t *offset) { char *ts; int type = -1; @@ -381,7 +370,6 @@ int mod_expire_plugin_init(plugin *p) { p->init = mod_expire_init; p->handle_response_start = mod_expire_handler; p->set_defaults = mod_expire_set_defaults; - p->cleanup = mod_expire_free; return 0; } diff --git a/src/mod_extforward.c b/src/mod_extforward.c index fdad9648..f96a8a53 100644 --- a/src/mod_extforward.c +++ b/src/mod_extforward.c @@ -142,7 +142,9 @@ INIT_FUNC(mod_extforward_init) { return calloc(1, sizeof(plugin_data)); } -static void mod_extforward_free_config(plugin_data * const p) { +FREE_FUNC(mod_extforward_free) { + plugin_data * const p = p_d; + array_free(p->default_headers); if (NULL == p->cvlist) return; /* (init i to 0 if global context; to 1 to skip empty global context) */ for (int i = !p->cvlist[0].v.u2[1], used = p->nconfig; i < used; ++i) { @@ -159,20 +161,6 @@ static void mod_extforward_free_config(plugin_data * const p) { } } -FREE_FUNC(mod_extforward_free) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - UNUSED(srv); - - mod_extforward_free_config(p); - array_free(p->default_headers); - - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; -} - static void mod_extforward_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { switch (cpv->k_id) { /* index into static config_plugin_keys_t cpk[] */ case 0: /* extforward.forwarder */ diff --git a/src/mod_flv_streaming.c b/src/mod_flv_streaming.c index 96e6cf71..291bd3fc 100644 --- a/src/mod_flv_streaming.c +++ b/src/mod_flv_streaming.c @@ -26,17 +26,6 @@ INIT_FUNC(mod_flv_streaming_init) { return calloc(1, sizeof(plugin_data)); } -FREE_FUNC(mod_flv_streaming_free) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - UNUSED(srv); - - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; -} - static void mod_flv_streaming_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { switch (cpv->k_id) { /* index into static config_plugin_keys_t cpk[] */ case 0: /* flv-streaming.extensions */ @@ -171,7 +160,6 @@ int mod_flv_streaming_plugin_init(plugin *p) { p->init = mod_flv_streaming_init; p->handle_physical = mod_flv_streaming_path_handler; p->set_defaults = mod_flv_streaming_set_defaults; - p->cleanup = mod_flv_streaming_free; return 0; } diff --git a/src/mod_geoip.c b/src/mod_geoip.c index b987bd9a..b870bd63 100644 --- a/src/mod_geoip.c +++ b/src/mod_geoip.c @@ -69,7 +69,8 @@ INIT_FUNC(mod_geoip_init) { return calloc(1, sizeof(plugin_data)); } -static void mod_geoip_free_config(plugin_data * const p) { +FREE_FUNC(mod_geoip_free) { + plugin_data * const p = p_d; if (NULL == p->cvlist) return; /* (init i to 0 if global context; to 1 to skip empty global context) */ for (int i = !p->cvlist[0].v.u2[1], used = p->nconfig; i < used; ++i) { @@ -87,19 +88,6 @@ static void mod_geoip_free_config(plugin_data * const p) { } } -FREE_FUNC(mod_geoip_free) { - plugin_data * const p = p_d; - if (!p) return HANDLER_GO_ON; - UNUSED(srv); - - mod_geoip_free_config(p); - - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; -} - static int mod_geoip_open_db(server *srv, config_plugin_value_t * const cpv, int mem_cache) { /* country db filename is required! */ if (buffer_is_empty(cpv->v.b)) { diff --git a/src/mod_indexfile.c b/src/mod_indexfile.c index d3ba3442..57aa7c20 100644 --- a/src/mod_indexfile.c +++ b/src/mod_indexfile.c @@ -30,17 +30,6 @@ INIT_FUNC(mod_indexfile_init) { return calloc(1, sizeof(plugin_data)); } -FREE_FUNC(mod_indexfile_free) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - UNUSED(srv); - - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; -} - static void mod_indexfile_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { switch (cpv->k_id) { /* index into static config_plugin_keys_t cpk[] */ case 0: /* index-file.names */ @@ -192,7 +181,6 @@ int mod_indexfile_plugin_init(plugin *p) { p->init = mod_indexfile_init; p->handle_subrequest_start = mod_indexfile_subrequest; p->set_defaults = mod_indexfile_set_defaults; - p->cleanup = mod_indexfile_free; return 0; } diff --git a/src/mod_magnet.c b/src/mod_magnet.c index 1631cc0c..7839d028 100644 --- a/src/mod_magnet.c +++ b/src/mod_magnet.c @@ -49,15 +49,7 @@ INIT_FUNC(mod_magnet_init) { FREE_FUNC(mod_magnet_free) { plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - UNUSED(srv); - script_cache_free_data(&p->cache); - - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; } static void mod_magnet_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { diff --git a/src/mod_maxminddb.c b/src/mod_maxminddb.c index c72fe438..7579c2b8 100644 --- a/src/mod_maxminddb.c +++ b/src/mod_maxminddb.c @@ -107,8 +107,9 @@ INIT_FUNC(mod_maxminddb_init) } -static void mod_maxminddb_free_config (plugin_data * const p) +FREE_FUNC(mod_maxminddb_free) { + plugin_data * const p = p_d; if (NULL == p->cvlist) return; /* (init i to 0 if global context; to 1 to skip empty global context) */ for (int i = !p->cvlist[0].v.u2[1], used = p->nconfig; i < used; ++i) { @@ -142,21 +143,6 @@ static void mod_maxminddb_free_config (plugin_data * const p) } -FREE_FUNC(mod_maxminddb_free) -{ - plugin_data * const p = p_d; - if (!p) return HANDLER_GO_ON; - UNUSED(srv); - - mod_maxminddb_free_config(p); - - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; -} - - static MMDB_s * mod_maxminddb_open_db (server *srv, const buffer *db_name) { diff --git a/src/mod_mysql_vhost.c b/src/mod_mysql_vhost.c index 7b2de53b..88f6f7a3 100644 --- a/src/mod_mysql_vhost.c +++ b/src/mod_mysql_vhost.c @@ -27,7 +27,6 @@ typedef struct { const buffer *mysql_query; } plugin_config; -/* global plugin data */ typedef struct { PLUGIN_DATA; plugin_config defaults; @@ -36,19 +35,19 @@ typedef struct { buffer tmp_buf; } plugin_data; -/* per connection plugin data */ typedef struct { buffer *server_name; buffer *document_root; } plugin_connection_data; -/* init the plugin data */ INIT_FUNC(mod_mysql_vhost_init) { return calloc(1, sizeof(plugin_data)); } /* cleanup the mysql connections */ -static void mod_mysql_vhost_free_config(plugin_data * const p) { +FREE_FUNC(mod_mysql_vhost_cleanup) { + plugin_data * const p = p_d; + free(p->tmp_buf.ptr); if (NULL == p->cvlist) return; /* (init i to 0 if global context; to 1 to skip empty global context) */ for (int i = !p->cvlist[0].v.u2[1], used = p->nconfig; i < used; ++i) { @@ -66,22 +65,6 @@ static void mod_mysql_vhost_free_config(plugin_data * const p) { } } -/* cleanup the plugin data */ -FREE_FUNC(mod_mysql_vhost_cleanup) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - - mod_mysql_vhost_free_config(p); - free(p->tmp_buf.ptr); - - free(p->cvlist); - free(p); - - UNUSED(srv); - return HANDLER_GO_ON; -} - -/* handle the plugin per connection data */ static void* mod_mysql_vhost_connection_data(server *srv, connection *con, void *p_d) { plugin_data *p = p_d; @@ -98,7 +81,6 @@ static void* mod_mysql_vhost_connection_data(server *srv, connection *con, void return con->plugin_ctx[p->id] = c; } -/* destroy the plugin per connection data */ CONNECTION_FUNC(mod_mysql_vhost_handle_connection_reset) { plugin_data *p = p_d; plugin_connection_data *c = con->plugin_ctx[p->id]; @@ -192,7 +174,6 @@ static MYSQL * mod_mysql_vhost_db_setup (server *srv, const char *dbname, const return my; } -/* set configuration values */ SETDEFAULTS_FUNC(mod_mysql_vhost_set_defaults) { static const config_plugin_keys_t cpk[] = { { CONST_STR_LEN("mysql-vhost.sql"), @@ -285,7 +266,6 @@ SETDEFAULTS_FUNC(mod_mysql_vhost_set_defaults) { return HANDLER_GO_ON; } -/* handle document root request */ CONNECTION_FUNC(mod_mysql_vhost_handle_docroot) { plugin_data *p = p_d; plugin_connection_data *c; @@ -385,7 +365,7 @@ ERR500: return HANDLER_FINISHED; } -/* this function is called at dlopen() time and inits the callbacks */ + int mod_mysql_vhost_plugin_init(plugin *p); int mod_mysql_vhost_plugin_init(plugin *p) { p->version = LIGHTTPD_VERSION_ID; diff --git a/src/mod_openssl.c b/src/mod_openssl.c index cc7c03b5..e106dc5b 100644 --- a/src/mod_openssl.c +++ b/src/mod_openssl.c @@ -104,6 +104,7 @@ typedef struct { PLUGIN_DATA; plugin_ssl_ctx *ssl_ctxs; plugin_config defaults; + server *srv; array *cafiles; } plugin_data; @@ -284,16 +285,9 @@ mod_openssl_load_ca_files (SSL_CTX *ssl_ctx, plugin_data *p, server *srv) FREE_FUNC(mod_openssl_free) { plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - UNUSED(srv); - - mod_openssl_free_config(srv, p); + if (NULL == p->srv) return; + mod_openssl_free_config(p->srv, p); mod_openssl_free_openssl(); - - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; } @@ -1581,6 +1575,7 @@ SETDEFAULTS_FUNC(mod_openssl_set_defaults) }; plugin_data * const p = p_d; + p->srv = srv; p->cafiles = array_init(); if (!config_plugin_values_init(srv, p, cpk, "mod_openssl")) return HANDLER_ERROR; diff --git a/src/mod_proxy.c b/src/mod_proxy.c index 69d226fe..fdc0c4fb 100644 --- a/src/mod_proxy.c +++ b/src/mod_proxy.c @@ -92,12 +92,9 @@ static void mod_proxy_free_config(plugin_data * const p) FREE_FUNC(mod_proxy_free) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - + plugin_data * const p = p_d; mod_proxy_free_config(p); - - return gw_free(srv, p); + gw_free(p); } static void mod_proxy_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) diff --git a/src/mod_redirect.c b/src/mod_redirect.c index 48675733..97b03408 100644 --- a/src/mod_redirect.c +++ b/src/mod_redirect.c @@ -27,7 +27,8 @@ INIT_FUNC(mod_redirect_init) { return calloc(1, sizeof(plugin_data)); } -static void mod_redirect_free_config(plugin_data * const p) { +FREE_FUNC(mod_redirect_free) { + plugin_data * const p = p_d; if (NULL == p->cvlist) return; /* (init i to 0 if global context; to 1 to skip empty global context) */ for (int i = !p->cvlist[0].v.u2[1], used = p->nconfig; i < used; ++i) { @@ -45,19 +46,6 @@ static void mod_redirect_free_config(plugin_data * const p) { } } -FREE_FUNC(mod_redirect_free) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - UNUSED(srv); - - mod_redirect_free_config(p); - - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; -} - static void mod_redirect_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { switch (cpv->k_id) { /* index into static config_plugin_keys_t cpk[] */ case 0: /* url.redirect */ diff --git a/src/mod_rewrite.c b/src/mod_rewrite.c index 9fe5cb64..2c0a4d96 100644 --- a/src/mod_rewrite.c +++ b/src/mod_rewrite.c @@ -29,7 +29,8 @@ INIT_FUNC(mod_rewrite_init) { return calloc(1, sizeof(plugin_data)); } -static void mod_rewrite_free_config(plugin_data * const p) { +FREE_FUNC(mod_rewrite_free) { + plugin_data * const p = p_d; if (NULL == p->cvlist) return; /* (init i to 0 if global context; to 1 to skip empty global context) */ for (int i = !p->cvlist[0].v.u2[1], used = p->nconfig; i < used; ++i) { @@ -58,19 +59,6 @@ static void mod_rewrite_free_config(plugin_data * const p) { } } -FREE_FUNC(mod_rewrite_free) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - UNUSED(srv); - - mod_rewrite_free_config(p); - - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; -} - static void mod_rewrite_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { switch (cpv->k_id) { /* index into static config_plugin_keys_t cpk[] */ case 0: /* url.rewrite-once */ diff --git a/src/mod_rrdtool.c b/src/mod_rrdtool.c index d0e6ed02..4f27ca87 100644 --- a/src/mod_rrdtool.c +++ b/src/mod_rrdtool.c @@ -39,6 +39,7 @@ typedef struct { int rrdtool_running; const buffer *path_rrdtool_bin; + server *srv; } plugin_data; INIT_FUNC(mod_rrd_init) { @@ -64,22 +65,15 @@ static void mod_rrd_free_config(plugin_data * const p) { FREE_FUNC(mod_rrd_free) { plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - UNUSED(srv); - + if (NULL == p->srv) return; mod_rrd_free_config(p); if (p->read_fd >= 0) close(p->read_fd); if (p->write_fd >= 0) close(p->write_fd); - if (p->rrdtool_pid > 0 && p->srv_pid == srv->pid) { + if (p->rrdtool_pid > 0 && p->srv_pid == p->srv->pid) { /* collect status (blocking) */ while (-1 == waitpid(p->rrdtool_pid, NULL, 0) && errno == EINTR) ; } - - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; } static int mod_rrd_create_pipe(server *srv, plugin_data *p) { @@ -179,6 +173,7 @@ SETDEFAULTS_FUNC(mod_rrd_set_defaults) { }; plugin_data * const p = p_d; + p->srv = srv; if (!config_plugin_values_init(srv, p, cpk, "mod_rrdtool")) return HANDLER_ERROR; diff --git a/src/mod_secdownload.c b/src/mod_secdownload.c index 6d0f8130..82f03b32 100644 --- a/src/mod_secdownload.c +++ b/src/mod_secdownload.c @@ -229,17 +229,6 @@ INIT_FUNC(mod_secdownload_init) { return calloc(1, sizeof(plugin_data)); } -FREE_FUNC(mod_secdownload_free) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - UNUSED(srv); - - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; -} - static int mod_secdownload_parse_algorithm(server * const srv, config_plugin_value_t * const cpv) { secdl_algorithm algorithm = algorithm_from_string(cpv->v.b); switch (algorithm) { @@ -549,7 +538,6 @@ int mod_secdownload_plugin_init(plugin *p) { p->init = mod_secdownload_init; p->handle_physical = mod_secdownload_uri_handler; p->set_defaults = mod_secdownload_set_defaults; - p->cleanup = mod_secdownload_free; return 0; } diff --git a/src/mod_setenv.c b/src/mod_setenv.c index 63197834..5a9eb5d8 100644 --- a/src/mod_setenv.c +++ b/src/mod_setenv.c @@ -45,17 +45,6 @@ INIT_FUNC(mod_setenv_init) { return calloc(1, sizeof(plugin_data)); } -FREE_FUNC(mod_setenv_free) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - UNUSED(srv); - - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; -} - static void mod_setenv_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { switch (cpv->k_id) { /* index into static config_plugin_keys_t cpk[] */ case 0: /* setenv.add-request-header */ @@ -285,7 +274,6 @@ int mod_setenv_plugin_init(plugin *p) { p->handle_request_env = mod_setenv_handle_request_env; p->handle_response_start = mod_setenv_handle_response_start; p->set_defaults = mod_setenv_set_defaults; - p->cleanup = mod_setenv_free; p->connection_reset = mod_setenv_reset; diff --git a/src/mod_simple_vhost.c b/src/mod_simple_vhost.c index a238fe18..4d56b786 100644 --- a/src/mod_simple_vhost.c +++ b/src/mod_simple_vhost.c @@ -33,16 +33,8 @@ INIT_FUNC(mod_simple_vhost_init) { FREE_FUNC(mod_simple_vhost_free) { plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - UNUSED(srv); - free(p->tmp_buf.ptr); free(p->last_root.ptr); - - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; } static void mod_simple_vhost_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { diff --git a/src/mod_skeleton.c b/src/mod_skeleton.c index 9754fe8d..ca91b75a 100644 --- a/src/mod_skeleton.c +++ b/src/mod_skeleton.c @@ -59,18 +59,6 @@ INIT_FUNC(mod_skeleton_init) { return calloc(1, sizeof(plugin_data)); } -/* destroy the plugin data */ -FREE_FUNC(mod_skeleton_free) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - UNUSED(srv); - - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; -} - /* handle plugin config and check values */ static void mod_skeleton_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { @@ -170,7 +158,6 @@ int mod_skeleton_plugin_init(plugin *p) { p->version = LIGHTTPD_VERSION_ID; p->name = "skeleton"; p->init = mod_skeleton_init; - p->cleanup = mod_skeleton_free; p->set_defaults= mod_skeleton_set_defaults; p->handle_uri_clean = mod_skeleton_uri_handler; diff --git a/src/mod_ssi.c b/src/mod_ssi.c index eabf512a..8ba4342f 100644 --- a/src/mod_ssi.c +++ b/src/mod_ssi.c @@ -72,19 +72,10 @@ INIT_FUNC(mod_ssi_init) { FREE_FUNC(mod_ssi_free) { plugin_data *p = p_d; - UNUSED(srv); - - if (!p) return HANDLER_GO_ON; - array_free(p->ssi_vars); array_free(p->ssi_cgi_env); buffer_free(p->timefmt); buffer_free(p->stat_fn); - - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; } static void mod_ssi_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { diff --git a/src/mod_staticfile.c b/src/mod_staticfile.c index cb5fdc35..0e640c44 100644 --- a/src/mod_staticfile.c +++ b/src/mod_staticfile.c @@ -33,17 +33,6 @@ INIT_FUNC(mod_staticfile_init) { return calloc(1, sizeof(plugin_data)); } -FREE_FUNC(mod_staticfile_free) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - UNUSED(srv); - - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; -} - static void mod_staticfile_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { switch (cpv->k_id) { /* index into static config_plugin_keys_t cpk[] */ case 0: /* static-file.exclude-extensions */ @@ -183,7 +172,6 @@ int mod_staticfile_plugin_init(plugin *p) { p->init = mod_staticfile_init; p->handle_subrequest_start = mod_staticfile_subrequest; p->set_defaults = mod_staticfile_set_defaults; - p->cleanup = mod_staticfile_free; return 0; } diff --git a/src/mod_status.c b/src/mod_status.c index c94e74c5..fe5ce9b6 100644 --- a/src/mod_status.c +++ b/src/mod_status.c @@ -50,17 +50,6 @@ INIT_FUNC(mod_status_init) { return calloc(1, sizeof(plugin_data)); } -FREE_FUNC(mod_status_free) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - UNUSED(srv); - - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; -} - static void mod_status_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { switch (cpv->k_id) { /* index into static config_plugin_keys_t cpk[] */ case 0: /* status.status-url */ @@ -899,7 +888,6 @@ int mod_status_plugin_init(plugin *p) { p->name = "status"; p->init = mod_status_init; - p->cleanup = mod_status_free; p->set_defaults= mod_status_set_defaults; p->handle_uri_clean = mod_status_handler; diff --git a/src/mod_trigger_b4_dl.c b/src/mod_trigger_b4_dl.c index 3aa38286..178f276d 100644 --- a/src/mod_trigger_b4_dl.c +++ b/src/mod_trigger_b4_dl.c @@ -59,7 +59,8 @@ INIT_FUNC(mod_trigger_b4_dl_init) { return calloc(1, sizeof(plugin_data)); } -static void mod_trigger_b4_dl_free_config(plugin_data * const p) { +FREE_FUNC(mod_trigger_b4_dl_free) { + plugin_data *p = p_d; if (NULL == p->cvlist) return; /* (init i to 0 if global context; to 1 to skip empty global context) */ for (int i = !p->cvlist[0].v.u2[1], used = p->nconfig; i < used; ++i) { @@ -183,19 +184,6 @@ static int mod_trigger_b4_dl_init_regex(server * const srv, config_plugin_value_ } } -FREE_FUNC(mod_trigger_b4_dl_free) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - UNUSED(srv); - - mod_trigger_b4_dl_free_config(p); - - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; -} - static void mod_trigger_b4_dl_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { switch (cpv->k_id) { /* index into static config_plugin_keys_t cpk[] */ case 0: /* trigger-before-download.gdbm-filename */ diff --git a/src/mod_uploadprogress.c b/src/mod_uploadprogress.c index 8ec101bd..e7a5ddac 100644 --- a/src/mod_uploadprogress.c +++ b/src/mod_uploadprogress.c @@ -127,15 +127,7 @@ INIT_FUNC(mod_uploadprogress_init) { FREE_FUNC(mod_uploadprogress_free) { plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - UNUSED(srv); - connection_map_free_data(&p->con_map); - - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; } static void mod_uploadprogress_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { diff --git a/src/mod_userdir.c b/src/mod_userdir.c index 995becc6..0c95bbf6 100644 --- a/src/mod_userdir.c +++ b/src/mod_userdir.c @@ -37,17 +37,6 @@ INIT_FUNC(mod_userdir_init) { return calloc(1, sizeof(plugin_data)); } -FREE_FUNC(mod_userdir_free) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - UNUSED(srv); - - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; -} - static void mod_userdir_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { switch (cpv->k_id) { /* index into static config_plugin_keys_t cpk[] */ case 0: /* userdir.path */ @@ -315,7 +304,6 @@ int mod_userdir_plugin_init(plugin *p) { p->init = mod_userdir_init; p->handle_physical = mod_userdir_docroot_handler; p->set_defaults = mod_userdir_set_defaults; - p->cleanup = mod_userdir_free; return 0; } diff --git a/src/mod_usertrack.c b/src/mod_usertrack.c index 8ee31bc3..2b4a3333 100644 --- a/src/mod_usertrack.c +++ b/src/mod_usertrack.c @@ -30,17 +30,6 @@ INIT_FUNC(mod_usertrack_init) { return calloc(1, sizeof(plugin_data)); } -FREE_FUNC(mod_usertrack_free) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - UNUSED(srv); - - free(p->cvlist); - free(p); - - return HANDLER_GO_ON; -} - static void mod_usertrack_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { switch (cpv->k_id) { /* index into static config_plugin_keys_t cpk[] */ case 0: /* usertrack.cookie-name */ @@ -250,7 +239,6 @@ int mod_usertrack_plugin_init(plugin *p) { p->init = mod_usertrack_init; p->handle_uri_clean = mod_usertrack_uri_handler; p->set_defaults = mod_usertrack_set_defaults; - p->cleanup = mod_usertrack_free; return 0; } diff --git a/src/mod_vhostdb.c b/src/mod_vhostdb.c index c6fb30dc..a127c27f 100644 --- a/src/mod_vhostdb.c +++ b/src/mod_vhostdb.c @@ -32,15 +32,7 @@ INIT_FUNC(mod_vhostdb_init) { FREE_FUNC(mod_vhostdb_free) { plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - free(p->tmp_buf.ptr); - - free(p->cvlist); - free(p); - - UNUSED(srv); - return HANDLER_GO_ON; } static void mod_vhostdb_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { diff --git a/src/mod_vhostdb_dbi.c b/src/mod_vhostdb_dbi.c index 5ca19ffb..aaa70bf3 100644 --- a/src/mod_vhostdb_dbi.c +++ b/src/mod_vhostdb_dbi.c @@ -233,7 +233,8 @@ INIT_FUNC(mod_vhostdb_init) { return p; } -static void mod_vhostdb_free_config(plugin_data * const p) { +FREE_FUNC(mod_vhostdb_cleanup) { + plugin_data * const p = p_d; if (NULL == p->cvlist) return; /* (init i to 0 if global context; to 1 to skip empty global context) */ for (int i = !p->cvlist[0].v.u2[1], used = p->nconfig; i < used; ++i) { @@ -251,19 +252,6 @@ static void mod_vhostdb_free_config(plugin_data * const p) { } } -FREE_FUNC(mod_vhostdb_cleanup) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - - mod_vhostdb_free_config(p); - - free(p->cvlist); - free(p); - - UNUSED(srv); - return HANDLER_GO_ON; -} - static void mod_vhostdb_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { switch (cpv->k_id) { /* index into static config_plugin_keys_t cpk[] */ case 0: /* vhostdb. */ diff --git a/src/mod_vhostdb_ldap.c b/src/mod_vhostdb_ldap.c index ffee2a9b..90c19d44 100644 --- a/src/mod_vhostdb_ldap.c +++ b/src/mod_vhostdb_ldap.c @@ -459,7 +459,8 @@ INIT_FUNC(mod_vhostdb_init) { return p; } -static void mod_vhostdb_free_config(plugin_data * const p) { +FREE_FUNC(mod_vhostdb_cleanup) { + plugin_data * const p = p_d; if (NULL == p->cvlist) return; /* (init i to 0 if global context; to 1 to skip empty global context) */ for (int i = !p->cvlist[0].v.u2[1], used = p->nconfig; i < used; ++i) { @@ -477,19 +478,6 @@ static void mod_vhostdb_free_config(plugin_data * const p) { } } -FREE_FUNC(mod_vhostdb_cleanup) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - - mod_vhostdb_free_config(p); - - free(p->cvlist); - free(p); - - UNUSED(srv); - return HANDLER_GO_ON; -} - static void mod_vhostdb_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { switch (cpv->k_id) { /* index into static config_plugin_keys_t cpk[] */ case 0: /* vhostdb. */ diff --git a/src/mod_vhostdb_mysql.c b/src/mod_vhostdb_mysql.c index bd5b84dd..766ee8e9 100644 --- a/src/mod_vhostdb_mysql.c +++ b/src/mod_vhostdb_mysql.c @@ -194,7 +194,8 @@ INIT_FUNC(mod_vhostdb_init) { return p; } -static void mod_vhostdb_free_config(plugin_data * const p) { +FREE_FUNC(mod_vhostdb_cleanup) { + plugin_data * const p = p_d; if (NULL == p->cvlist) return; /* (init i to 0 if global context; to 1 to skip empty global context) */ for (int i = !p->cvlist[0].v.u2[1], used = p->nconfig; i < used; ++i) { @@ -212,19 +213,6 @@ static void mod_vhostdb_free_config(plugin_data * const p) { } } -FREE_FUNC(mod_vhostdb_cleanup) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - - mod_vhostdb_free_config(p); - - free(p->cvlist); - free(p); - - UNUSED(srv); - return HANDLER_GO_ON; -} - static void mod_vhostdb_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { switch (cpv->k_id) { /* index into static config_plugin_keys_t cpk[] */ case 0: /* vhostdb. */ diff --git a/src/mod_vhostdb_pgsql.c b/src/mod_vhostdb_pgsql.c index 49ab1953..3dad465a 100644 --- a/src/mod_vhostdb_pgsql.c +++ b/src/mod_vhostdb_pgsql.c @@ -171,7 +171,8 @@ INIT_FUNC(mod_vhostdb_init) { return p; } -static void mod_vhostdb_free_config(plugin_data * const p) { +FREE_FUNC(mod_vhostdb_cleanup) { + plugin_data * const p = p_d; if (NULL == p->cvlist) return; /* (init i to 0 if global context; to 1 to skip empty global context) */ for (int i = !p->cvlist[0].v.u2[1], used = p->nconfig; i < used; ++i) { @@ -189,19 +190,6 @@ static void mod_vhostdb_free_config(plugin_data * const p) { } } -FREE_FUNC(mod_vhostdb_cleanup) { - plugin_data *p = p_d; - if (!p) return HANDLER_GO_ON; - - mod_vhostdb_free_config(p); - - free(p->cvlist); - free(p); - - UNUSED(srv); - return HANDLER_GO_ON; -} - static void mod_vhostdb_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { switch (cpv->k_id) { /* index into static config_plugin_keys_t cpk[] */ case 0: /* vhostdb. */ diff --git a/src/mod_webdav.c b/src/mod_webdav.c index 658ca494..333109a7 100644 --- a/src/mod_webdav.c +++ b/src/mod_webdav.c @@ -330,7 +330,8 @@ INIT_FUNC(mod_webdav_init) { } -static void mod_webdav_free_config(plugin_data * const p) { +FREE_FUNC(mod_webdav_free) { + plugin_data * const p = (plugin_data *)p_d; if (NULL == p->cvlist) return; /* (init i to 0 if global context; to 1 to skip empty global context) */ for (int i = !p->cvlist[0].v.u2[1], used = p->nconfig; i < used; ++i) { @@ -378,19 +379,6 @@ static void mod_webdav_free_config(plugin_data * const p) { } -FREE_FUNC(mod_webdav_free) { - plugin_data *p = (plugin_data *)p_d; - if (!p) return HANDLER_GO_ON; - - mod_webdav_free_config(p); - - free(p->cvlist); - free(p); - UNUSED(srv); - return HANDLER_GO_ON; -} - - static void mod_webdav_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) { switch (cpv->k_id) { /* index into static config_plugin_keys_t cpk[] */ case 0: /* webdav.sqlite-db-name */ diff --git a/src/plugin.c b/src/plugin.c index 980aaae6..ee458ff3 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -41,8 +41,8 @@ typedef enum { PLUGIN_FUNC_HANDLE_DOCROOT, PLUGIN_FUNC_HANDLE_PHYSICAL, PLUGIN_FUNC_CONNECTION_RESET, - PLUGIN_FUNC_INIT, - PLUGIN_FUNC_CLEANUP, + /* PLUGIN_FUNC_INIT, *//* handled here in plugin.c */ + /* PLUGIN_FUNC_CLEANUP, *//* handled here in plugin.c */ PLUGIN_FUNC_SET_DEFAULTS, PLUGIN_FUNC_WORKER_INIT, @@ -347,7 +347,6 @@ PLUGIN_CALL_FN_SRV_CON_DATA(PLUGIN_FUNC_CONNECTION_RESET, connection_reset) PLUGIN_CALL_FN_SRV_DATA(PLUGIN_FUNC_HANDLE_TRIGGER, handle_trigger) PLUGIN_CALL_FN_SRV_DATA(PLUGIN_FUNC_HANDLE_SIGHUP, handle_sighup) -PLUGIN_CALL_FN_SRV_DATA(PLUGIN_FUNC_CLEANUP, cleanup) PLUGIN_CALL_FN_SRV_DATA(PLUGIN_FUNC_SET_DEFAULTS, set_defaults) PLUGIN_CALL_FN_SRV_DATA(PLUGIN_FUNC_WORKER_INIT, worker_init) @@ -365,6 +364,22 @@ handler_t plugins_call_handle_waitpid(server *srv, pid_t pid, int status) { return rc; } +static void plugins_call_cleanup(server * const srv) { + plugin ** const ps = srv->plugins.ptr; + for (uint32_t i = 0; i < srv->plugins.used; ++i) { + plugin *p = ps[i]; + if (NULL == p) continue; + if (NULL != p->data) { + plugin_data_base *pd = p->data; + if (p->cleanup) + p->cleanup(p->data); + free(pd->cvlist); + free(pd); + p->data = NULL; + } + } +} + /** * * - call init function of all plugins to init the plugin-internals @@ -447,8 +462,6 @@ handler_t plugins_call_init(server *srv) { ++offsets[PLUGIN_FUNC_HANDLE_PHYSICAL]; if (p->connection_reset) ++offsets[PLUGIN_FUNC_CONNECTION_RESET]; - if (p->cleanup) - ++offsets[PLUGIN_FUNC_CLEANUP]; if (p->set_defaults) ++offsets[PLUGIN_FUNC_SET_DEFAULTS]; if (p->worker_init) @@ -506,8 +519,6 @@ handler_t plugins_call_init(server *srv) { offsets[PLUGIN_FUNC_HANDLE_PHYSICAL]); plugins_call_init_slot(srv, p->connection_reset, p->data, offsets[PLUGIN_FUNC_CONNECTION_RESET]); - plugins_call_init_slot(srv, p->cleanup, p->data, - offsets[PLUGIN_FUNC_CLEANUP]); plugins_call_init_slot(srv, p->set_defaults, p->data, offsets[PLUGIN_FUNC_SET_DEFAULTS]); plugins_call_init_slot(srv, p->worker_init, p->data, diff --git a/src/plugin.h b/src/plugin.h index 127e05d3..b42c0724 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -17,7 +17,10 @@ __attribute_cold__ \ static void *x(void) -#define FREE_FUNC __attribute_cold__ SERVER_FUNC +#define FREE_FUNC(x) \ + __attribute_cold__ \ + static void x(void *p_d) + #define SETDEFAULTS_FUNC __attribute_cold__ SERVER_FUNC #define SIGHUP_FUNC __attribute_cold__ SERVER_FUNC #define TRIGGER_FUNC SERVER_FUNC @@ -60,7 +63,7 @@ typedef struct { handler_t (* priv_defaults) (server *srv, void *p_d); handler_t (* set_defaults) (server *srv, void *p_d); handler_t (* worker_init) (server *srv, void *p_d); /* at server startup (each worker after fork()) */ - handler_t (* cleanup) (server *srv, void *p_d); + void (* cleanup) (void *p_d); const char *name;/* name of the plugin */ size_t version; @@ -102,7 +105,4 @@ handler_t plugins_call_set_defaults(server *srv); __attribute_cold__ handler_t plugins_call_worker_init(server *srv); -__attribute_cold__ -handler_t plugins_call_cleanup(server *srv); - #endif