summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-07-31 20:44:34 +0200
committerwm4 <wm4@nowhere>2013-07-31 20:55:59 +0200
commita8a0c5023b915897066cc72c472eb9def0b34efb (patch)
tree8d534308371a091ab61a0281aa353322a0c32356
parent0656411e97afd5710b02563ee0b28423443592e9 (diff)
downloadmpv-a8a0c5023b915897066cc72c472eb9def0b34efb.tar.bz2
mpv-a8a0c5023b915897066cc72c472eb9def0b34efb.tar.xz
m_config: remove alias information
We don't need to store anymore whether an option is aliased by another option (which is what the alias_owner member did). Also, that member had a really bad name. This also removes some unneeded code from config_destroy(). Calling m_option_free() is always ok; this just skipped the call if it did nothing. In particular, it's ok to call m_option_free() on the same pointer multiple times. (Maybe that function is misnamed, and it should be m_option_clear().)
-rw-r--r--core/m_config.c32
-rw-r--r--core/m_config.h4
2 files changed, 12 insertions, 24 deletions
diff --git a/core/m_config.c b/core/m_config.c
index 7faca24497..dda55fb107 100644
--- a/core/m_config.c
+++ b/core/m_config.c
@@ -184,13 +184,8 @@ static int config_destroy(void *p)
struct m_config *config = p;
if (config->file_local_mode)
m_config_leave_file_local(config);
- for (struct m_config_option *copt = config->opts; copt; copt = copt->next) {
- if (copt->alias_owner)
- continue;
- if (copt->opt->type->flags & M_OPT_TYPE_DYNAMIC) {
- m_option_free(copt->opt, copt->data);
- }
- }
+ for (struct m_config_option *copt = config->opts; copt; copt = copt->next)
+ m_option_free(copt->opt, copt->data);
return 0;
}
@@ -422,19 +417,8 @@ static struct m_config_option *m_config_add_option(struct m_config *config,
add_options(config, co, sub);
}
} else {
- // Check if there is already an option pointing to this address
+ // Initialize options
if (co->data) {
- for (struct m_config_option *i = config->opts; i; i = i->next) {
- if (co->data == i->data) {
- // So we don't save the same vars more than 1 time
- co->alias_owner = i;
- break;
- }
- }
- }
- if (co->alias_owner) {
- assert(!arg->defval);
- } else {
if (arg->defval) {
// Target data in optstruct is supposed to be cleared (consider
// m_option freeing previously set dynamic data).
@@ -444,7 +428,15 @@ static struct m_config_option *m_config_add_option(struct m_config *config,
// string options): copy the option into temporary memory,
// clear the original option (to stop m_option from freeing the
// static data), copy it back.
- if (co->data) {
+ // 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);
diff --git a/core/m_config.h b/core/m_config.h
index 1ee7ecf1c0..dbc334c3aa 100644
--- a/core/m_config.h
+++ b/core/m_config.h
@@ -46,10 +46,6 @@ struct m_config_option {
void *data;
// If this is a suboption, the option that contains this option.
struct m_config_option *parent;
- // If this option aliases another, more important option. The alias_owner
- // option is the one that has the most correct option type for the data
- // variable, and which is considered the original.
- struct m_config_option *alias_owner;
};
// Config object