options: Make dynamic dup hack work with new options

The option system has a hack that converts default values (potentially
constants) of dynamically allocated options to allocated ones when the
options are first added to the config system, so that all values can
be equally freed later. Make this work with new-style options in the
option struct too.
This commit is contained in:
Uoti Urpala 2008-04-30 19:34:26 +03:00
parent e61ac5e9cb
commit bb12a33f9a
1 changed files with 7 additions and 4 deletions

View File

@ -229,11 +229,14 @@ m_config_add_option(m_config_t *config, const m_option_t *arg, const char* prefi
m_option_save(config, arg, sl->data);
// Hack to avoid too much trouble with dynamically allocated data :
// We always use a dynamic version
if ((arg->type->flags & M_OPT_TYPE_DYNAMIC) && arg->p
&& (*(void**)arg->p)) {
*(void**)arg->p = NULL;
if ((arg->type->flags & M_OPT_TYPE_DYNAMIC)) {
char **hackptr = arg->new ? (char*)config->optstruct + arg->offset
: arg->p;
if (hackptr && *hackptr) {
*hackptr = NULL;
m_option_set(config, arg, sl->data);
}
}
sl->lvl = 0;
sl->prev = NULL;
co->slots = talloc_zero_size(co, sizeof(m_config_save_slot_t) +