m_config: don't allow aliasing with string options

Minor simplification. String options are now not allowed to use the
same variable/field anymore. (Also affects other "dynamic" options
which require memory allocation.)
This commit is contained in:
wm4 2013-10-24 19:11:27 +02:00
parent cc235d203d
commit 8d5f8d5a6b
1 changed files with 7 additions and 12 deletions

View File

@ -422,20 +422,15 @@ static struct m_config_option *m_config_add_option(struct m_config *config,
// clear the original option (to stop m_option from freeing the
// static data), copy it back.
// This would leak memory when done on aliased options.
bool aliased = false;
for (struct m_config_option *i = config->opts; i; i = i->next) {
if (co->data == i->data) {
aliased = true;
break;
}
}
if (!aliased) {
union m_option_value temp = {0};
m_option_copy(arg, &temp, co->data);
memset(co->data, 0, arg->type->size);
m_option_copy(arg, co->data, &temp);
m_option_free(arg, &temp);
if (co->data == i->data)
assert(0);
}
union m_option_value temp = {0};
m_option_copy(arg, &temp, co->data);
memset(co->data, 0, arg->type->size);
m_option_copy(arg, co->data, &temp);
m_option_free(arg, &temp);
}
}
}