diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-04-29 08:47:51 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-05-06 16:54:06 +0200 |
commit | be32732168e07b7d52ec77fa67cf93a80a9a8293 (patch) | |
tree | 0feb0a006050702078fd41b5fea2eee9c4d00b08 /src/analyze | |
parent | 0894f08bf14b09ef0436ed11268d43dbcdd88ee7 (diff) | |
download | systemd-be32732168e07b7d52ec77fa67cf93a80a9a8293.tar.gz |
basic/set: let set_put_strdup() create the set with string hash ops
If we're using a set with _put_strdup(), most of the time we want to use
string hash ops on the set, and free the strings when done. This defines
the appropriate a new string_hash_ops_free structure to automatically free
the keys when removing the set, and makes set_put_strdup() and set_put_strdupv()
instantiate the set with those hash ops.
hashmap_put_strdup() was already doing something similar.
(It is OK to instantiate the set earlier, possibly with a different hash ops
structure. set_put_strdup() will then use the existing set. It is also OK
to call set_free_free() instead of set_free() on a set with
string_hash_ops_free, the effect is the same, we're just overriding the
override of the cleanup function.)
No functional change intended.
Diffstat (limited to 'src/analyze')
-rw-r--r-- | src/analyze/analyze-security.c | 8 | ||||
-rw-r--r-- | src/analyze/analyze.c | 10 |
2 files changed, 5 insertions, 13 deletions
diff --git a/src/analyze/analyze-security.c b/src/analyze/analyze-security.c index d681251c04..0137883976 100644 --- a/src/analyze/analyze-security.c +++ b/src/analyze/analyze-security.c @@ -141,7 +141,7 @@ static void security_info_free(struct security_info *i) { strv_free(i->supplementary_groups); strv_free(i->system_call_architectures); - set_free_free(i->system_call_filter); + set_free(i->system_call_filter); } static bool security_info_runs_privileged(const struct security_info *i) { @@ -1728,11 +1728,7 @@ static int property_read_system_call_filter( if (r == 0) break; - r = set_ensure_allocated(&info->system_call_filter, &string_hash_ops); - if (r < 0) - return r; - - r = set_put_strdup(info->system_call_filter, name); + r = set_put_strdup(&info->system_call_filter, name); if (r < 0) return r; } diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index 3ea9041c18..3e7740593d 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -1655,7 +1655,7 @@ static int dump_exit_status(int argc, char *argv[], void *userdata) { #if HAVE_SECCOMP static int load_kernel_syscalls(Set **ret) { - _cleanup_(set_free_freep) Set *syscalls = NULL; + _cleanup_set_free_ Set *syscalls = NULL; _cleanup_fclose_ FILE *f = NULL; int r; @@ -1691,11 +1691,7 @@ static int load_kernel_syscalls(Set **ret) { if (STR_IN_SET(e, "newuname", "newfstat", "newstat", "newlstat", "sysctl")) continue; - r = set_ensure_allocated(&syscalls, &string_hash_ops); - if (r < 0) - return log_oom(); - - r = set_put_strdup(syscalls, e); + r = set_put_strdup(&syscalls, e); if (r < 0) return log_error_errno(r, "Failed to add system call to list: %m"); } @@ -1735,7 +1731,7 @@ static int dump_syscall_filters(int argc, char *argv[], void *userdata) { (void) pager_open(arg_pager_flags); if (strv_isempty(strv_skip(argv, 1))) { - _cleanup_(set_free_freep) Set *kernel = NULL; + _cleanup_set_free_ Set *kernel = NULL; int i, k; k = load_kernel_syscalls(&kernel); |