diff options
Diffstat (limited to 'src/xine-engine/configfile.c')
-rw-r--r-- | src/xine-engine/configfile.c | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/src/xine-engine/configfile.c b/src/xine-engine/configfile.c index 2dc89f0af..81acab348 100644 --- a/src/xine-engine/configfile.c +++ b/src/xine-engine/configfile.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2000-2004 the xine project + * Copyright (C) 2000-2008 the xine project * * This file is part of xine, a free video player. * @@ -319,11 +319,11 @@ static void config_insert(config_values_t *this, cfg_entry_t *new_entry) { this->first = new_entry; } -static cfg_entry_t *config_add (config_values_t *this, const char *key, int exp_level) { +static cfg_entry_t *XINE_MALLOC config_add (config_values_t *this, const char *key, int exp_level) { cfg_entry_t *entry; - entry = (cfg_entry_t *) xine_xmalloc (sizeof (cfg_entry_t)); + entry = calloc (1, sizeof (cfg_entry_t)); entry->config = this; entry->key = strdup(key); entry->type = XINE_CONFIG_TYPE_UNKNOWN; @@ -356,22 +356,22 @@ static const char *config_xlate_internal (const char *key, const xine_config_ent return NULL; } -static const char *config_translate_key (const char *key) { +static const char *config_translate_key (const char *key, char **tmp) { /* Returns translated key or, if no translation found, NULL. * Translated key may be in a static buffer allocated within this function. * NOT re-entrant; assumes that config_lock is held. */ unsigned trans; - static char *newkey = NULL; + const char *newkey = NULL; /* first, special-case the decoder entries (so that new ones can be added * without requiring modification of the translation table) */ + *tmp = NULL; if (!strncmp (key, "decoder.", 8) && !strcmp (key + (trans = strlen (key)) - 9, "_priority")) { - newkey = realloc (newkey, trans + 27 - 17); /* diff. in string lengths */ - sprintf (newkey, "engine.decoder_priorities.%.*s", trans - 17, key + 8); - return newkey; + asprintf (tmp, "engine.decoder_priorities.%.*s", trans - 17, key + 8); + return *tmp; } /* search the translation table... */ @@ -386,6 +386,7 @@ static void config_lookup_entry_int (config_values_t *this, const char *key, cfg_entry_t **entry, cfg_entry_t **prev) { int trans; + char *tmp = NULL; /* try twice at most (second time with translation from old key name) */ for (trans = 2; trans; --trans) { @@ -397,14 +398,18 @@ static void config_lookup_entry_int (config_values_t *this, const char *key, *entry = (*entry)->next; } - if (*entry) + if (*entry) { + free(tmp); return; + } /* we did not find a match, maybe this is an old config entry name * trying to translate */ - key = config_translate_key(key); - if (!key) + key = config_translate_key(key, &tmp); + if (!key) { + free(tmp); return; + } } } @@ -748,7 +753,7 @@ static int config_register_enum (config_values_t *this, entry->type = XINE_CONFIG_TYPE_ENUM; if (entry->unknown_value) - entry->num_value = config_parse_enum (entry->unknown_value, values); + entry->num_value = config_parse_enum (entry->unknown_value, (const char **)values); else entry->num_value = def_value; @@ -756,14 +761,14 @@ static int config_register_enum (config_values_t *this, entry->num_default = def_value; /* allocate and copy the enum values */ - value_src = values; + value_src = (const char **)values; value_count = 0; while (*value_src) { value_src++; value_count++; } entry->enum_values = malloc (sizeof(char*) * (value_count + 1)); - value_src = values; + value_src = (const char **)values; value_dest = entry->enum_values; while (*value_src) { *value_dest = strdup(*value_src); @@ -862,7 +867,7 @@ static void config_update_string (config_values_t *this, /* if an enum is updated with a string, we convert the string to * its index and use update number */ if (entry->type == XINE_CONFIG_TYPE_ENUM) { - config_update_num(this, key, config_parse_enum(value, entry->enum_values)); + config_update_num(this, key, config_parse_enum(value, (const char **)entry->enum_values)); return; } @@ -944,15 +949,17 @@ void xine_config_load (xine_t *xine, const char *filename) { if (!(entry = config_lookup_entry(this, line))) { const char *key = line; + char *tmp = NULL; pthread_mutex_lock(&this->config_lock); if (this->current_version < CONFIG_FILE_VERSION) { /* old config file -> let's see if we have to rename this one */ - key = config_translate_key(key); + key = config_translate_key(key, &tmp); if (!key) key = line; /* no translation? fall back on untranslated key */ } entry = config_add (this, key, 50); entry->unknown_value = strdup(value); + free(tmp); pthread_mutex_unlock(&this->config_lock); } else { switch (entry->type) { @@ -1005,7 +1012,7 @@ void xine_config_save (xine_t *xine, const char *filename) { char *buf = NULL; size_t rlen; - buf = (char *) xine_xmalloc(config_stat.st_size + 1); + buf = (char *) malloc(config_stat.st_size + 1); if((rlen = fread(buf, 1, config_stat.st_size, f_config)) && ((off_t)rlen == config_stat.st_size)) { (void) fwrite(buf, 1, rlen, f_backup); } @@ -1204,7 +1211,7 @@ config_values_t *_x_config_init (void) { config_values_t *this; pthread_mutexattr_t attr; - if (!(this = xine_xmalloc(sizeof(config_values_t)))) { + if (!(this = calloc(1, sizeof(config_values_t)))) { printf ("configfile: could not allocate config object\n"); _x_abort(); |