From: Zbigniew Jędrzejewski-Szmek Date: Fri, 5 Jun 2020 12:06:02 +0000 (+0200) Subject: portable: rework set handling in portable_detach() X-Git-Tag: v246-rc1~105^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d378ef708b123b5da9ce2a52ea9e8a838f63bddb;p=thirdparty%2Fsystemd.git portable: rework set handling in portable_detach() _cleanup_set_free_ is enough for unit_files, because unit_files is allocated in set_put_strdup(), which uses string_hash_ops_free. This fixes a leak if marker was already present in the table. --- diff --git a/src/portable/portable.c b/src/portable/portable.c index 57c224decd0..3dc6d9e4220 100644 --- a/src/portable/portable.c +++ b/src/portable/portable.c @@ -1125,7 +1125,7 @@ int portable_detach( sd_bus_error *error) { _cleanup_(lookup_paths_free) LookupPaths paths = {}; - _cleanup_set_free_free_ Set *unit_files = NULL, *markers = NULL; + _cleanup_set_free_ Set *unit_files = NULL, *markers = NULL; _cleanup_closedir_ DIR *d = NULL; const char *where, *item; Iterator iterator; @@ -1149,10 +1149,6 @@ int portable_detach( return log_debug_errno(errno, "Failed to open '%s' directory: %m", where); } - markers = set_new(&path_hash_ops); - if (!markers) - return -ENOMEM; - FOREACH_DIRENT(de, d, return log_debug_errno(errno, "Failed to enumerate '%s' directory: %m", where)) { _cleanup_free_ char *marker = NULL; UnitFileState state; @@ -1193,10 +1189,8 @@ int portable_detach( if (path_is_absolute(marker) && !image_in_search_path(IMAGE_PORTABLE, marker)) { - r = set_ensure_put(&markers, &path_hash_ops, marker); - if (r >= 0) - marker = NULL; - else if (r != -EEXIST) + r = set_ensure_consume(&markers, &path_hash_ops_free, TAKE_PTR(marker)); + if (r < 0) return r; } }