From b4d64ac43432f99ff20357226c8b41a2e71583f7 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 26 Jun 2014 19:13:37 +0200 Subject: config, player: avoid some temporary talloc contexts IMO a semi-bad concept, that the mpv code unfortunately uses way too much. --- options/path.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'options/path.c') diff --git a/options/path.c b/options/path.c index eaae35154f..0c3a7ba335 100644 --- a/options/path.c +++ b/options/path.c @@ -136,21 +136,22 @@ char *mp_find_config_file(void *talloc_ctx, struct mpv_global *global, { struct MPOpts *opts = global->opts; - void *tmp = talloc_new(NULL); char *res = NULL; if (opts->load_config) { - for (char **dir = mp_config_dirs(tmp, global); *dir; dir++) { - char *config_file = talloc_asprintf(tmp, "%s/%s", *dir, filename); + char **dirs = mp_config_dirs(NULL, global); + for (int i = 0; dirs && dirs[i]; i++) { + char *file = talloc_asprintf(talloc_ctx, "%s/%s", dirs[i], filename); - if (mp_path_exists(config_file)) { - res = talloc_strdup(talloc_ctx, config_file); + if (mp_path_exists(file)) { + res = file; break; } + + talloc_free(file); } + talloc_free(dirs); } - talloc_free(tmp); - MP_VERBOSE(global, "config path: '%s' -> '%s'\n", filename, res ? res : "(NULL)"); return res; @@ -165,15 +166,16 @@ char **mp_find_all_config_files(void *talloc_ctx, struct mpv_global *global, int num_ret = 0; if (opts->load_config) { - char **dir = mp_config_dirs(NULL, global); - for (int i = 0; dir && dir[i]; i++) { - char *file = talloc_asprintf(ret, "%s/%s", dir[i], filename); + char **dirs = mp_config_dirs(NULL, global); + for (int i = 0; dirs && dirs[i]; i++) { + char *file = talloc_asprintf(ret, "%s/%s", dirs[i], filename); if (!mp_path_exists(file) || num_ret >= MAX_CONFIG_PATHS) continue; ret[num_ret++] = file; } + talloc_free(dirs); } for (int n = 0; n < num_ret / 2; n++) @@ -331,8 +333,7 @@ bstr mp_split_proto(bstr path, bstr *out_url) void mp_mkdirp(const char *dir) { - void *tmp = talloc_new(NULL); - char *path = talloc_strdup(tmp, dir); + char *path = talloc_strdup(NULL, dir); char *cdir = path + 1; while (cdir) { @@ -346,7 +347,7 @@ void mp_mkdirp(const char *dir) *cdir++ = '/'; } - talloc_free(tmp); + talloc_free(path); } void mp_mk_config_dir(struct mpv_global *global, char *subdir) -- cgit v1.2.3