diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2016-04-13 21:10:33 -0400 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2016-04-13 21:10:33 -0400 |
commit | e215d211d25139a46970101525ebdde874daf2f0 (patch) | |
tree | d7ad3f12cb324c640d268132eb86dca19425d6ee /src/shared | |
parent | ea9b54f827feff046d7d6e5c485d01cf98214762 (diff) |
shared/path-lookup: fix leak
CID #1354671: char **l would be leaked.
Also rename l to paths, to make the code easier to read,
and do strv deduplication immediately when extending. No need to allocate
strings to remove them a few lines down.
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/path-lookup.c | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/src/shared/path-lookup.c b/src/shared/path-lookup.c index 167108ee1b..80a2ea7940 100644 --- a/src/shared/path-lookup.c +++ b/src/shared/path-lookup.c @@ -451,7 +451,7 @@ int lookup_paths_init( *transient = NULL, *persistent_control = NULL, *runtime_control = NULL; bool append = false; /* Add items from SYSTEMD_UNIT_PATH before normal directories */ - char **l = NULL; + _cleanup_strv_free_ char **paths = NULL; const char *e; int r; @@ -506,13 +506,12 @@ int lookup_paths_init( /* FIXME: empty components in other places should be * rejected. */ - r = path_split_and_make_absolute(e, &l); + r = path_split_and_make_absolute(e, &paths); if (r < 0) return r; - } else - l = NULL; + } - if (!l || append) { + if (!paths || append) { /* Let's figure something out. */ _cleanup_strv_free_ char **add = NULL; @@ -587,14 +586,9 @@ int lookup_paths_init( if (!add) return -ENOMEM; - if (l) { - r = strv_extend_strv(&l, add, false); - if (r < 0) + r = strv_extend_strv(&paths, add, true); + if (r < 0) return r; - } else { - l = add; - add = NULL; - } } r = patch_root_prefix(&persistent_config, root); @@ -626,12 +620,12 @@ int lookup_paths_init( if (r < 0) return r; - r = patch_root_prefix_strv(l, root); + r = patch_root_prefix_strv(paths, root); if (r < 0) return -ENOMEM; - p->search_path = strv_uniq(l); - l = NULL; + p->search_path = strv_uniq(paths); + paths = NULL; p->persistent_config = persistent_config; p->runtime_config = runtime_config; |