*/
static int dynamic_modules = 0;
+/* The maximum possible value for total_modulese, i.e. number of static
+ * modules plus DYNAMIC_MODULE_LIMIT.
+ */
+static int max_modules = 0;
+
+/* The number of elements we need to alloc for config vectors. Before loading
+ * of dynamic modules, we must be liberal and set this to max_modules. After
+ * loading of dynamic modules, we can trim it down to total_modules. On
+ * restart, reset to max_modules.
+ */
+static int conf_vector_length = 0;
+
AP_DECLARE_DATA module *ap_top_module = NULL;
AP_DECLARE_DATA module **ap_loaded_modules=NULL;
static ap_conf_vector_t *create_empty_config(apr_pool_t *p)
{
- void *conf_vector = apr_pcalloc(p, sizeof(void *) *
- (total_modules + DYNAMIC_MODULE_LIMIT));
+ void *conf_vector = apr_pcalloc(p, sizeof(void *) * conf_vector_length);
return conf_vector;
}
static ap_conf_vector_t *create_default_per_dir_config(apr_pool_t *p)
{
- void **conf_vector = apr_pcalloc(p, sizeof(void *) *
- (total_modules + DYNAMIC_MODULE_LIMIT));
+ void **conf_vector = apr_pcalloc(p, sizeof(void *) * conf_vector_length);
module *modp;
for (modp = ap_top_module; modp; modp = modp->next) {
ap_conf_vector_t *base,
ap_conf_vector_t *new_conf)
{
- void **conf_vector = apr_palloc(p, sizeof(void *) * total_modules);
+ void **conf_vector = apr_palloc(p, sizeof(void *) * conf_vector_length);
void **base_vector = (void **)base;
void **new_vector = (void **)new_conf;
module *modp;
static ap_conf_vector_t *create_server_config(apr_pool_t *p, server_rec *s)
{
- void **conf_vector = apr_pcalloc(p, sizeof(void *) *
- (total_modules + DYNAMIC_MODULE_LIMIT));
+ void **conf_vector = apr_pcalloc(p, sizeof(void *) * conf_vector_length);
module *modp;
for (modp = ap_top_module; modp; modp = modp->next) {
for (m = ap_preloaded_modules; *m != NULL; m++)
(*m)->module_index = total_modules++;
+ max_modules = total_modules + DYNAMIC_MODULE_LIMIT + 1;
+ conf_vector_length = max_modules;
+
/*
* Initialise list of loaded modules
*/
ap_loaded_modules = (module **)apr_palloc(process->pool,
- sizeof(module *) * (total_modules + DYNAMIC_MODULE_LIMIT + 1));
+ sizeof(module *) * conf_vector_length);
if (ap_loaded_modules == NULL) {
return "Ouch! Out of memory in ap_setup_prelinked_modules()!";
{
if (l->module_levels) {
int i;
- for (i = 0; i < total_modules + DYNAMIC_MODULE_LIMIT; i++)
+ for (i = 0; i < conf_vector_length; i++)
l->module_levels[i] = val;
}
}
int index, int level)
{
if (!l->module_levels) {
- l->module_levels = apr_palloc(pool,
- sizeof(int) * (total_modules + DYNAMIC_MODULE_LIMIT));
+ l->module_levels = apr_palloc(pool, sizeof(int) * conf_vector_length);
if (l->level == APLOG_UNSET) {
ap_reset_module_loglevels(l, APLOG_UNSET);
}
l->level = old->level;
if (old->module_levels) {
l->module_levels =
- apr_pmemdup(p, old->module_levels,
- sizeof(int) * (total_modules + DYNAMIC_MODULE_LIMIT));
+ apr_pmemdup(p, old->module_levels, sizeof(int) * conf_vector_length);
}
}
else {
}
else if (old->module_levels != NULL) {
int i;
- for (i = 0; i < total_modules + DYNAMIC_MODULE_LIMIT; i++) {
+ for (i = 0; i < conf_vector_length; i++) {
if (new->module_levels[i] == APLOG_UNSET)
new->module_levels[i] = old->module_levels[i];
}
}
+static apr_status_t reset_conf_vector_length(void *dummy)
+{
+ conf_vector_length = max_modules;
+ return APR_SUCCESS;
+}
+
AP_DECLARE(server_rec*) ap_read_config(process_rec *process, apr_pool_t *ptemp,
const char *filename,
ap_directive_t **conftree)
return NULL;
}
+ /*
+ * We have loaded the dynamic modules. From now on we know exactly how
+ * long the config vectors need to be.
+ */
+ conf_vector_length = total_modules;
+ apr_pool_cleanup_register(p, NULL, reset_conf_vector_length,
+ apr_pool_cleanup_null);
+
error = process_command_config(s, ap_server_post_read_config, conftree,
p, ptemp);