diff options
author | Jaroslav Kysela <perex@perex.cz> | 2019-01-07 13:15:32 +0100 |
---|---|---|
committer | Jaroslav Kysela <perex@perex.cz> | 2019-01-07 13:15:34 +0100 |
commit | 1e5ecbc806a001f6aca34168e5b7e91ee74d2c62 (patch) | |
tree | 4b5d79098050e0e55f96196d99dfa8119c1b15d2 | |
parent | f664a7aec9a249503e8523c6d830f60e3eb77cf6 (diff) |
conf: rename snd_conf_load1() to _snd_config_load_with_include()
Always free the include path which must be mallocated by the caller.
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
-rw-r--r-- | include/local.h | 2 | ||||
-rw-r--r-- | src/conf.c | 39 | ||||
-rw-r--r-- | src/ucm/utils.c | 29 |
3 files changed, 29 insertions, 41 deletions
diff --git a/include/local.h b/include/local.h index 03d8f0cc..e2cc291e 100644 --- a/include/local.h +++ b/include/local.h @@ -355,7 +355,7 @@ int snd_config_search_alias_hooks(snd_config_t *config, int _snd_conf_generic_id(const char *id); int _snd_config_load_with_include(snd_config_t *config, snd_input_t *in, - const char *default_include_path); + int override, char *default_include_path); /* convenience macros */ #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) @@ -1832,16 +1832,19 @@ int snd_config_top(snd_config_t **config) return _snd_config_make(config, 0, SND_CONFIG_TYPE_COMPOUND); } -static int snd_config_load1(snd_config_t *config, snd_input_t *in, int override, - char *default_include_path) +#ifndef DOC_HIDDEN +int _snd_config_load_with_include(snd_config_t *config, snd_input_t *in, + int override, char *default_include_path) { int err; input_t input; struct filedesc *fd, *fd_next; assert(config && in); fd = malloc(sizeof(*fd)); - if (!fd) - return -ENOMEM; + if (!fd) { + err = -ENOMEM; + goto _end_inc; + } fd->name = NULL; fd->in = in; fd->line = 1; @@ -1852,6 +1855,7 @@ static int snd_config_load1(snd_config_t *config, snd_input_t *in, int override, err = add_include_path(fd, default_include_path); if (err < 0) goto _end; + default_include_path = NULL; } input.current = fd; input.unget = 0; @@ -1900,8 +1904,11 @@ static int snd_config_load1(snd_config_t *config, snd_input_t *in, int override, free_include_paths(fd); free(fd); + _end_inc: + free(default_include_path); return err; } +#endif /** * \brief Loads a configuration tree. @@ -1921,28 +1928,8 @@ static int snd_config_load1(snd_config_t *config, snd_input_t *in, int override, */ int snd_config_load(snd_config_t *config, snd_input_t *in) { - return snd_config_load1(config, in, 0, NULL); -} - -#ifndef DOC_HIDDEN -/* load config with the default include path; used internally for UCM parser */ -int _snd_config_load_with_include(snd_config_t *config, snd_input_t *in, - const char *default_include_path) -{ - int err; - char *s = NULL; - - if (default_include_path) { - s = strdup(default_include_path); - if (!s) - return -ENOMEM; - } - err = snd_config_load1(config, in, 0, s); - if (err < 0) - free(s); - return err; + return _snd_config_load_with_include(config, in, 0, NULL); } -#endif /** * \brief Loads a configuration tree and overrides existing configuration nodes. @@ -1956,7 +1943,7 @@ int _snd_config_load_with_include(snd_config_t *config, snd_input_t *in, */ int snd_config_load_override(snd_config_t *config, snd_input_t *in) { - return snd_config_load1(config, in, 1, NULL); + return _snd_config_load_with_include(config, in, 1, NULL); } /** diff --git a/src/ucm/utils.c b/src/ucm/utils.c index ea5ac5dd..14227e0a 100644 --- a/src/ucm/utils.c +++ b/src/ucm/utils.c @@ -54,17 +54,12 @@ int uc_mgr_config_load(const char *file, snd_config_t **cfg) FILE *fp; snd_input_t *in; snd_config_t *top; - const char *default_path; + char *default_path; int err; fp = fopen(file, "r"); - if (fp == NULL) { - err = -errno; - goto __err; - } - err = snd_input_stdio_attach(&in, fp, 1); + err = fp == NULL ? -errno : snd_input_stdio_attach(&in, fp, 1); if (err < 0) { - __err: uc_error("could not open configuration file %s", file); return err; } @@ -75,19 +70,25 @@ int uc_mgr_config_load(const char *file, snd_config_t **cfg) default_path = getenv(ALSA_CONFIG_UCM_VAR); if (!default_path || !*default_path) default_path = ALSA_CONFIG_DIR "/ucm"; - err = _snd_config_load_with_include(top, in, default_path); + default_path = strdup(default_path); + if (!default_path) { + err = -ENOMEM; + goto __err2; + } + err = _snd_config_load_with_include(top, in, 0, default_path); if (err < 0) { uc_error("could not load configuration file %s", file); - snd_config_delete(top); - return err; + goto __err2; } err = snd_input_close(in); - if (err < 0) { - snd_config_delete(top); - return err; - } + if (err < 0) + goto __err2; *cfg = top; return 0; + + __err2: + snd_config_delete(top); + return err; } void uc_mgr_free_value(struct list_head *base) |