From f95c9f46e257ef335faaac14ff4db6477f950342 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 5 Oct 2023 18:58:55 +0200 Subject: [PATCH 1/3] nspawn: drop unnecessary wrapper functions The naming was confused: suffix 'p' means that the function takes a pointer to the type that the wrapped function takes. (E.g., a char**, for a wrapped function taking a char*.) But DEFINE_TRIVIAL_DESTRUCTOR() just changes the return type. Also add one more assert for consistency. --- src/nspawn/nspawn-oci.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/nspawn/nspawn-oci.c b/src/nspawn/nspawn-oci.c index 5bdfebde78..8075dd6829 100644 --- a/src/nspawn/nspawn-oci.c +++ b/src/nspawn/nspawn-oci.c @@ -509,14 +509,14 @@ typedef struct oci_mount_data { } oci_mount_data; static void oci_mount_data_done(oci_mount_data *data) { + assert(data); + free(data->destination); free(data->source); free(data->type); strv_free(data->options); } -DEFINE_TRIVIAL_DESTRUCTOR(oci_mount_data_donep, oci_mount_data, oci_mount_data_done); - static int oci_mounts(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { Settings *s = ASSERT_PTR(userdata); JsonVariant *e; @@ -532,7 +532,7 @@ static int oci_mounts(const char *name, JsonVariant *v, JsonDispatchFlags flags, }; _cleanup_free_ char *joined_options = NULL; - _cleanup_(oci_mount_data_donep) oci_mount_data data = {}; + _cleanup_(oci_mount_data_done) oci_mount_data data = {}; CustomMount *m; r = json_dispatch(e, table, oci_unexpected, flags, &data); @@ -614,14 +614,12 @@ struct namespace_data { char *path; }; -static void namespace_data_done(struct namespace_data *p) { - assert(p); +static void namespace_data_done(struct namespace_data *data) { + assert(data); - free(p->path); + free(data->path); } -DEFINE_TRIVIAL_DESTRUCTOR(namespace_data_donep, struct namespace_data, namespace_data_done); - static int oci_namespaces(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { Settings *s = ASSERT_PTR(userdata); unsigned long n = 0; @@ -629,7 +627,7 @@ static int oci_namespaces(const char *name, JsonVariant *v, JsonDispatchFlags fl int r; JSON_VARIANT_ARRAY_FOREACH(e, v) { - _cleanup_(namespace_data_donep) struct namespace_data data = {}; + _cleanup_(namespace_data_done) struct namespace_data data = {}; static const JsonDispatch table[] = { { "type", JSON_VARIANT_STRING, oci_namespace_type, offsetof(struct namespace_data, type), JSON_MANDATORY }, @@ -1744,8 +1742,6 @@ static void syscall_rule_done(struct syscall_rule *rule) { free(rule->arguments); }; -DEFINE_TRIVIAL_DESTRUCTOR(syscall_rule_donep, struct syscall_rule, syscall_rule_done); - static int oci_seccomp_action(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { uint32_t *action = ASSERT_PTR(userdata); int r; @@ -1829,7 +1825,7 @@ static int oci_seccomp_syscalls(const char *name, JsonVariant *v, JsonDispatchFl { "args", JSON_VARIANT_ARRAY, oci_seccomp_args, 0, 0 }, {} }; - _cleanup_(syscall_rule_donep) struct syscall_rule rule = { + _cleanup_(syscall_rule_done) struct syscall_rule rule = { .action = UINT32_MAX, }; From f6210525cca166029cac8b845ef166ed1dfc8e67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 5 Oct 2023 18:38:31 +0200 Subject: [PATCH 2/3] fuzz-bus-match: drop unnecessary wrapper function Same confusion as in previous commit. --- src/libsystemd/sd-bus/fuzz-bus-match.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libsystemd/sd-bus/fuzz-bus-match.c b/src/libsystemd/sd-bus/fuzz-bus-match.c index b79494d888..f7f12746e5 100644 --- a/src/libsystemd/sd-bus/fuzz-bus-match.c +++ b/src/libsystemd/sd-bus/fuzz-bus-match.c @@ -9,8 +9,6 @@ #include "fuzz.h" #include "memstream-util.h" -DEFINE_TRIVIAL_DESTRUCTOR(bus_match_donep, struct bus_match_node, bus_match_free); - int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { _cleanup_(memstream_done) MemStream m = {}; _cleanup_(sd_bus_unrefp) sd_bus *bus = NULL; @@ -28,7 +26,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { r = sd_bus_new(&bus); assert_se(r >= 0); - _cleanup_(bus_match_donep) struct bus_match_node root = { + _cleanup_(bus_match_free) struct bus_match_node root = { .type = BUS_MATCH_ROOT, }; From 3c4c109de1c3369cd86cdd3ed20fc5884bd28d3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 6 Oct 2023 16:45:30 +0200 Subject: [PATCH 3/3] basic/macro: add comment explaining DEFINE_TRIVIAL_DESTRUCTOR() --- src/basic/macro.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/basic/macro.h b/src/basic/macro.h index 0c99d68db2..7f650d0719 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -310,6 +310,8 @@ static inline int __coverity_check_and_return__(int condition) { #define FOREACH_ARRAY(i, array, num) \ _FOREACH_ARRAY(i, array, num, UNIQ_T(m, UNIQ), UNIQ_T(end, UNIQ)) +/* A wrapper for 'func' to return void. + * Only useful when a void-returning function is required by some API. */ #define DEFINE_TRIVIAL_DESTRUCTOR(name, type, func) \ static inline void name(type *p) { \ func(p); \