From e0bfdb9f461a21fe5b15dfc2c232c14cd4ad59a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Fri, 10 Nov 2023 03:26:36 +0100 Subject: [PATCH] spa: alsa: fix leaks in `get_data_path()` Coverity rightfully complains that assigning to `path` will lose its previous value leading to resource leaks. --- spa/plugins/alsa/acp/compat.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/spa/plugins/alsa/acp/compat.c b/spa/plugins/alsa/acp/compat.c index bccf745a4..e2f317b09 100644 --- a/spa/plugins/alsa/acp/compat.c +++ b/spa/plugins/alsa/acp/compat.c @@ -251,7 +251,6 @@ char *get_data_path(const char *data_dir, const char *data_type, const char *fna }; const char *e; spa_autofree char *base = NULL; - spa_autofree char *path = NULL; char *result; if (data_dir) @@ -271,18 +270,18 @@ char *get_data_path(const char *data_dir, const char *data_type, const char *fna base = get_xdg_home("XDG_CONFIG_HOME", ".config"); if (base) { SPA_FOR_EACH_ELEMENT_VAR(subpaths, subpath) { - path = spa_aprintf("%s/%s/%s", base, *subpath, data_type); + spa_autofree char *path = spa_aprintf("%s/%s/%s", base, *subpath, data_type); if ((result = try_path(fname, path)) != NULL) return result; } } SPA_FOR_EACH_ELEMENT_VAR(subpaths, subpath) { - path = spa_aprintf("/etc/%s/%s", *subpath, data_type); + spa_autofree char *path = spa_aprintf("/etc/%s/%s", *subpath, data_type); if ((result = try_path(fname, path)) != NULL) return result; } - path = spa_aprintf("%s/%s", PA_ALSA_DATA_DIR, data_type); + spa_autofree char *path = spa_aprintf("%s/%s", PA_ALSA_DATA_DIR, data_type); return pa_maybe_prefix_path(fname, path); }