From fd421c4adc7406de02e03e2f7ceede2cc6e1d9d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 16 Feb 2021 14:18:30 +0100 Subject: [PATCH] tree-wide: reset the cleaned-up variable in cleanup functions If the cleanup function returns the appropriate type, use that to reset the variable. For other functions (usually the foreign ones which return void), add an explicit value to reset to. This causes a bit of code churn, but I think it might be worth it. In a following patch static destructors will be called from a fuzzer, and this change allows them to be called multiple times. But I think such a change might help with detecting unitialized code reuse too. We hit various bugs like this, and things are more obvious when a pointer has been set to NULL. I was worried whether this change increases text size, but it doesn't seem to: -Dbuildtype=debug: before "tree-wide: return NULL from freeing functions": -rwxrwxr-x 1 zbyszek zbyszek 4117672 Feb 16 14:36 build/libsystemd.so.0.30.0* -rwxrwxr-x 1 zbyszek zbyszek 4494520 Feb 16 15:06 build/systemd* after "tree-wide: return NULL from freeing functions": -rwxrwxr-x 1 zbyszek zbyszek 4117672 Feb 16 14:36 build/libsystemd.so.0.30.0* -rwxrwxr-x 1 zbyszek zbyszek 4494576 Feb 16 15:10 build/systemd* now: -rwxrwxr-x 1 zbyszek zbyszek 4117672 Feb 16 14:36 build/libsystemd.so.0.30.0* -rwxrwxr-x 1 zbyszek zbyszek 4494640 Feb 16 15:15 build/systemd* -Dbuildtype=release: before "tree-wide: return NULL from freeing functions": -rwxrwxr-x 1 zbyszek zbyszek 5252256 Feb 14 14:47 build-rawhide/libsystemd.so.0.30.0* -rwxrwxr-x 1 zbyszek zbyszek 1834184 Feb 16 15:09 build-rawhide/systemd* after "tree-wide: return NULL from freeing functions": -rwxrwxr-x 1 zbyszek zbyszek 5252256 Feb 14 14:47 build-rawhide/libsystemd.so.0.30.0* -rwxrwxr-x 1 zbyszek zbyszek 1834184 Feb 16 15:10 build-rawhide/systemd* now: -rwxrwxr-x 1 zbyszek zbyszek 5252256 Feb 14 14:47 build-rawhide/libsystemd.so.0.30.0* -rwxrwxr-x 1 zbyszek zbyszek 1834184 Feb 16 15:16 build-rawhide/systemd* I would expect that the compiler would be able to elide the setting of a variable if the variable is never used again. And this seems to be the case: in optimized builds there is no change in size whatsoever. And the change in size in unoptimized build is negligible. Something strange is happening with size of libsystemd: it's bigger in optimized builds. Something to figure out, but unrelated to this patch. --- src/basic/capability-util.h | 2 +- src/basic/dlfcn-util.h | 2 +- src/basic/fd-util.h | 4 ++-- src/basic/fileio.c | 2 +- src/basic/gcrypt-util.h | 2 +- src/basic/macro.h | 10 ++++++++++ src/basic/selinux-util.c | 2 +- src/basic/selinux-util.h | 2 +- src/core/apparmor-setup.c | 6 +++--- src/core/socket.c | 2 +- src/home/homed-manager.c | 4 ++-- src/home/homework-luks.c | 8 ++++---- src/home/user-record-sign.c | 2 +- src/import/curl-util.h | 6 +++--- src/journal-remote/microhttpd-util.h | 4 ++-- src/journal/journalctl.c | 4 ++-- src/libsystemd/sd-journal/compress.c | 8 ++++---- src/partition/repart.c | 8 ++++---- src/resolve/resolved-dnstls-gnutls.c | 2 +- src/shared/acl-util.h | 8 ++++---- src/shared/blkid-util.h | 2 +- src/shared/cryptsetup-util.h | 4 ++-- src/shared/firewall-util-iptables.c | 2 +- src/shared/libmount-util.h | 4 ++-- src/shared/module-util.h | 2 +- src/shared/mount-util.h | 2 +- src/shared/openssl-util.h | 8 ++++---- src/shared/pkcs11-util.h | 4 ++-- src/shared/pwquality-util.h | 2 +- src/shared/seccomp-util.h | 2 +- src/udev/udev-ctrl.c | 2 +- 31 files changed, 66 insertions(+), 56 deletions(-) diff --git a/src/basic/capability-util.h b/src/basic/capability-util.h index f5ce290524..d9489d7883 100644 --- a/src/basic/capability-util.h +++ b/src/basic/capability-util.h @@ -25,7 +25,7 @@ int drop_privileges(uid_t uid, gid_t gid, uint64_t keep_capabilities); int drop_capability(cap_value_t cv); -DEFINE_TRIVIAL_CLEANUP_FUNC(cap_t, cap_free); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(cap_t, cap_free, NULL); #define _cleanup_cap_free_ _cleanup_(cap_freep) static inline void cap_free_charpp(char **p) { diff --git a/src/basic/dlfcn-util.h b/src/basic/dlfcn-util.h index e0944f3aaf..aa713d328b 100644 --- a/src/basic/dlfcn-util.h +++ b/src/basic/dlfcn-util.h @@ -5,7 +5,7 @@ #include "macro.h" -DEFINE_TRIVIAL_CLEANUP_FUNC(void*, dlclose); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(void*, dlclose, NULL); int dlsym_many_and_warn(void *dl, int level, ...); diff --git a/src/basic/fd-util.h b/src/basic/fd-util.h index 2162537b80..f05c2b5a15 100644 --- a/src/basic/fd-util.h +++ b/src/basic/fd-util.h @@ -41,8 +41,8 @@ static inline void fclosep(FILE **f) { safe_fclose(*f); } -DEFINE_TRIVIAL_CLEANUP_FUNC(FILE*, pclose); -DEFINE_TRIVIAL_CLEANUP_FUNC(DIR*, closedir); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(FILE*, pclose, NULL); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(DIR*, closedir, NULL); #define _cleanup_close_ _cleanup_(closep) #define _cleanup_fclose_ _cleanup_(fclosep) diff --git a/src/basic/fileio.c b/src/basic/fileio.c index f4708bc05f..21532515fb 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -1146,7 +1146,7 @@ static EndOfLineMarker categorize_eol(char c, ReadLineFlags flags) { return EOL_NONE; } -DEFINE_TRIVIAL_CLEANUP_FUNC(FILE*, funlockfile); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(FILE*, funlockfile, NULL); int read_line_full(FILE *f, size_t limit, ReadLineFlags flags, char **ret) { size_t n = 0, allocated = 0, count = 0; diff --git a/src/basic/gcrypt-util.h b/src/basic/gcrypt-util.h index c07b36cdb9..27dcc72028 100644 --- a/src/basic/gcrypt-util.h +++ b/src/basic/gcrypt-util.h @@ -14,7 +14,7 @@ void initialize_libgcrypt(bool secmem); int string_hashsum(const char *s, size_t len, int md_algorithm, char **out); -DEFINE_TRIVIAL_CLEANUP_FUNC(gcry_md_hd_t, gcry_md_close); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(gcry_md_hd_t, gcry_md_close, NULL); #endif static inline int string_hashsum_sha224(const char *s, size_t len, char **out) { diff --git a/src/basic/macro.h b/src/basic/macro.h index d4e3d3b8fb..eebd0769dd 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -405,10 +405,20 @@ static inline int __coverity_check_and_return__(int condition) { func(p); \ } +/* When func() returns the void value (NULL, -1, …) of the appropriate type */ #define DEFINE_TRIVIAL_CLEANUP_FUNC(type, func) \ static inline void func##p(type *p) { \ if (*p) \ + *p = func(*p); \ + } + +/* When func() doesn't return the appropriate type, set variable to empty afterwards */ +#define DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(type, func, empty) \ + static inline void func##p(type *p) { \ + if (*p != (empty)) { \ func(*p); \ + *p = (empty); \ + } \ } #define _DEFINE_TRIVIAL_REF_FUNC(type, name, scope) \ diff --git a/src/basic/selinux-util.c b/src/basic/selinux-util.c index bd22500b7e..cfc8464c66 100644 --- a/src/basic/selinux-util.c +++ b/src/basic/selinux-util.c @@ -29,7 +29,7 @@ #include "time-util.h" #if HAVE_SELINUX -DEFINE_TRIVIAL_CLEANUP_FUNC(context_t, context_free); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(context_t, context_free, NULL); #define _cleanup_context_free_ _cleanup_(context_freep) static int mac_selinux_reload(int seqno); diff --git a/src/basic/selinux-util.h b/src/basic/selinux-util.h index 1236d6efdf..1095bdef0e 100644 --- a/src/basic/selinux-util.h +++ b/src/basic/selinux-util.h @@ -11,7 +11,7 @@ #if HAVE_SELINUX #include -DEFINE_TRIVIAL_CLEANUP_FUNC(char*, freecon); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(char*, freecon, NULL); #define _cleanup_freecon_ _cleanup_(freeconp) #endif diff --git a/src/core/apparmor-setup.c b/src/core/apparmor-setup.c index e856f5c183..304a3e6aac 100644 --- a/src/core/apparmor-setup.c +++ b/src/core/apparmor-setup.c @@ -16,17 +16,17 @@ #include "strv.h" #if HAVE_APPARMOR -DEFINE_TRIVIAL_CLEANUP_FUNC(aa_policy_cache *, aa_policy_cache_unref); -DEFINE_TRIVIAL_CLEANUP_FUNC(aa_features *, aa_features_unref); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(aa_policy_cache *, aa_policy_cache_unref, NULL); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(aa_features *, aa_features_unref, NULL); #endif int mac_apparmor_setup(void) { #if HAVE_APPARMOR - int r; _cleanup_(aa_policy_cache_unrefp) aa_policy_cache *policy_cache = NULL; _cleanup_(aa_features_unrefp) aa_features *features = NULL; const char *current_file; _cleanup_free_ char *current_profile = NULL, *cache_dir_path = NULL; + int r; if (!mac_apparmor_use()) { log_debug("AppArmor either not supported by the kernel or disabled."); diff --git a/src/core/socket.c b/src/core/socket.c index 5631054cce..e9cacfdf3a 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -1611,7 +1611,7 @@ static int socket_address_listen_in_cgroup( return fd; } -DEFINE_TRIVIAL_CLEANUP_FUNC(Socket *, socket_close_fds); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(Socket *, socket_close_fds, NULL); static int socket_open_fds(Socket *orig_s) { _cleanup_(socket_close_fdsp) Socket *s = orig_s; diff --git a/src/home/homed-manager.c b/src/home/homed-manager.c index 91cabd5cef..1b13002627 100644 --- a/src/home/homed-manager.c +++ b/src/home/homed-manager.c @@ -1343,7 +1343,7 @@ static int manager_load_key_pair(Manager *m) { return 1; } -DEFINE_TRIVIAL_CLEANUP_FUNC(EVP_PKEY_CTX*, EVP_PKEY_CTX_free); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(EVP_PKEY_CTX*, EVP_PKEY_CTX_free, NULL); static int manager_generate_key_pair(Manager *m) { _cleanup_(EVP_PKEY_CTX_freep) EVP_PKEY_CTX *ctx = NULL; @@ -1454,7 +1454,7 @@ int manager_sign_user_record(Manager *m, UserRecord *u, UserRecord **ret, sd_bus } DEFINE_PRIVATE_HASH_OPS_FULL(public_key_hash_ops, char, string_hash_func, string_compare_func, free, EVP_PKEY, EVP_PKEY_free); -DEFINE_TRIVIAL_CLEANUP_FUNC(EVP_PKEY*, EVP_PKEY_free); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(EVP_PKEY*, EVP_PKEY_free, NULL); static int manager_load_public_key_one(Manager *m, const char *path) { _cleanup_(EVP_PKEY_freep) EVP_PKEY *pkey = NULL; diff --git a/src/home/homework-luks.c b/src/home/homework-luks.c index c6b34d28d4..1d012c5d02 100644 --- a/src/home/homework-luks.c +++ b/src/home/homework-luks.c @@ -1592,10 +1592,10 @@ static int luks_format( return 0; } -DEFINE_TRIVIAL_CLEANUP_FUNC(struct fdisk_context*, fdisk_unref_context); -DEFINE_TRIVIAL_CLEANUP_FUNC(struct fdisk_partition*, fdisk_unref_partition); -DEFINE_TRIVIAL_CLEANUP_FUNC(struct fdisk_parttype*, fdisk_unref_parttype); -DEFINE_TRIVIAL_CLEANUP_FUNC(struct fdisk_table*, fdisk_unref_table); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct fdisk_context*, fdisk_unref_context, NULL); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct fdisk_partition*, fdisk_unref_partition, NULL); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct fdisk_parttype*, fdisk_unref_parttype, NULL); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct fdisk_table*, fdisk_unref_table, NULL); static int make_partition_table( int fd, diff --git a/src/home/user-record-sign.c b/src/home/user-record-sign.c index 8cd3a46251..5ac92255c8 100644 --- a/src/home/user-record-sign.c +++ b/src/home/user-record-sign.c @@ -27,7 +27,7 @@ static int user_record_signable_json(UserRecord *ur, char **ret) { return json_variant_format(j, 0, ret); } -DEFINE_TRIVIAL_CLEANUP_FUNC(EVP_MD_CTX*, EVP_MD_CTX_free); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(EVP_MD_CTX*, EVP_MD_CTX_free, NULL); int user_record_sign(UserRecord *ur, EVP_PKEY *private_key, UserRecord **ret) { _cleanup_(json_variant_unrefp) JsonVariant *encoded = NULL, *v = NULL; diff --git a/src/import/curl-util.h b/src/import/curl-util.h index 4ab52d73a4..6b4f992fe7 100644 --- a/src/import/curl-util.h +++ b/src/import/curl-util.h @@ -34,6 +34,6 @@ struct curl_slist *curl_slist_new(const char *first, ...) _sentinel_; int curl_header_strdup(const void *contents, size_t sz, const char *field, char **value); int curl_parse_http_time(const char *t, usec_t *ret); -DEFINE_TRIVIAL_CLEANUP_FUNC(CURL*, curl_easy_cleanup); -DEFINE_TRIVIAL_CLEANUP_FUNC(CURLM*, curl_multi_cleanup); -DEFINE_TRIVIAL_CLEANUP_FUNC(struct curl_slist*, curl_slist_free_all); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(CURL*, curl_easy_cleanup, NULL); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(CURLM*, curl_multi_cleanup, NULL); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct curl_slist*, curl_slist_free_all, NULL); diff --git a/src/journal-remote/microhttpd-util.h b/src/journal-remote/microhttpd-util.h index 7f90a09c77..a92ba57d0f 100644 --- a/src/journal-remote/microhttpd-util.h +++ b/src/journal-remote/microhttpd-util.h @@ -80,5 +80,5 @@ int check_permissions(struct MHD_Connection *connection, int *code, char **hostn */ int setup_gnutls_logger(char **categories); -DEFINE_TRIVIAL_CLEANUP_FUNC(struct MHD_Daemon*, MHD_stop_daemon); -DEFINE_TRIVIAL_CLEANUP_FUNC(struct MHD_Response*, MHD_destroy_response); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct MHD_Daemon*, MHD_stop_daemon, NULL); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct MHD_Response*, MHD_destroy_response, NULL); diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index a1b7bee2a3..3de3b4e26f 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -166,8 +166,8 @@ typedef struct BootId { } BootId; #if HAVE_PCRE2 -DEFINE_TRIVIAL_CLEANUP_FUNC(pcre2_match_data*, sym_pcre2_match_data_free); -DEFINE_TRIVIAL_CLEANUP_FUNC(pcre2_code*, sym_pcre2_code_free); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(pcre2_match_data*, sym_pcre2_match_data_free, NULL); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(pcre2_code*, sym_pcre2_code_free, NULL); static int pattern_compile(const char *pattern, unsigned flags, pcre2_code **out) { int errorcode, r; diff --git a/src/libsystemd/sd-journal/compress.c b/src/libsystemd/sd-journal/compress.c index 429dbadb6c..3ea3328c1e 100644 --- a/src/libsystemd/sd-journal/compress.c +++ b/src/libsystemd/sd-journal/compress.c @@ -34,13 +34,13 @@ #include "util.h" #if HAVE_LZ4 -DEFINE_TRIVIAL_CLEANUP_FUNC(LZ4F_compressionContext_t, LZ4F_freeCompressionContext); -DEFINE_TRIVIAL_CLEANUP_FUNC(LZ4F_decompressionContext_t, LZ4F_freeDecompressionContext); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(LZ4F_compressionContext_t, LZ4F_freeCompressionContext, NULL); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(LZ4F_decompressionContext_t, LZ4F_freeDecompressionContext, NULL); #endif #if HAVE_ZSTD -DEFINE_TRIVIAL_CLEANUP_FUNC(ZSTD_CCtx *, ZSTD_freeCCtx); -DEFINE_TRIVIAL_CLEANUP_FUNC(ZSTD_DCtx *, ZSTD_freeDCtx); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(ZSTD_CCtx*, ZSTD_freeCCtx, NULL); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(ZSTD_DCtx*, ZSTD_freeDCtx, NULL); static int zstd_ret_to_errno(size_t ret) { switch (ZSTD_getErrorCode(ret)) { diff --git a/src/partition/repart.c b/src/partition/repart.c index 78c31187ea..01e60e2133 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -1268,10 +1268,10 @@ static int context_read_definitions( return 0; } -DEFINE_TRIVIAL_CLEANUP_FUNC(struct fdisk_context*, fdisk_unref_context); -DEFINE_TRIVIAL_CLEANUP_FUNC(struct fdisk_partition*, fdisk_unref_partition); -DEFINE_TRIVIAL_CLEANUP_FUNC(struct fdisk_parttype*, fdisk_unref_parttype); -DEFINE_TRIVIAL_CLEANUP_FUNC(struct fdisk_table*, fdisk_unref_table); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct fdisk_context*, fdisk_unref_context, NULL); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct fdisk_partition*, fdisk_unref_partition, NULL); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct fdisk_parttype*, fdisk_unref_parttype, NULL); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct fdisk_table*, fdisk_unref_table, NULL); static int determine_current_padding( struct fdisk_context *c, diff --git a/src/resolve/resolved-dnstls-gnutls.c b/src/resolve/resolved-dnstls-gnutls.c index d3edd350b3..e7ccba934e 100644 --- a/src/resolve/resolved-dnstls-gnutls.c +++ b/src/resolve/resolved-dnstls-gnutls.c @@ -11,7 +11,7 @@ #include "resolved-manager.h" #define TLS_PROTOCOL_PRIORITY "NORMAL:-VERS-ALL:+VERS-TLS1.3:+VERS-TLS1.2" -DEFINE_TRIVIAL_CLEANUP_FUNC(gnutls_session_t, gnutls_deinit); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(gnutls_session_t, gnutls_deinit, NULL); static ssize_t dnstls_stream_writev(gnutls_transport_ptr_t p, const giovec_t *iov, int iovcnt) { int r; diff --git a/src/shared/acl-util.h b/src/shared/acl-util.h index 837e8699ee..03595c6651 100644 --- a/src/shared/acl-util.h +++ b/src/shared/acl-util.h @@ -21,13 +21,13 @@ int fd_add_uid_acl_permission(int fd, uid_t uid, unsigned mask); /* acl_free takes multiple argument types. * Multiple cleanup functions are necessary. */ -DEFINE_TRIVIAL_CLEANUP_FUNC(acl_t, acl_free); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(acl_t, acl_free, NULL); #define acl_free_charp acl_free -DEFINE_TRIVIAL_CLEANUP_FUNC(char*, acl_free_charp); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(char*, acl_free_charp, NULL); #define acl_free_uid_tp acl_free -DEFINE_TRIVIAL_CLEANUP_FUNC(uid_t*, acl_free_uid_tp); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(uid_t*, acl_free_uid_tp, NULL); #define acl_free_gid_tp acl_free -DEFINE_TRIVIAL_CLEANUP_FUNC(gid_t*, acl_free_gid_tp); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(gid_t*, acl_free_gid_tp, NULL); #else #define ACL_READ 0x04 diff --git a/src/shared/blkid-util.h b/src/shared/blkid-util.h index 3f38e9b308..aa444990fd 100644 --- a/src/shared/blkid-util.h +++ b/src/shared/blkid-util.h @@ -6,5 +6,5 @@ # include "macro.h" -DEFINE_TRIVIAL_CLEANUP_FUNC(blkid_probe, blkid_free_probe); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(blkid_probe, blkid_free_probe, NULL); #endif diff --git a/src/shared/cryptsetup-util.h b/src/shared/cryptsetup-util.h index 454bfa4532..5ebb0ac576 100644 --- a/src/shared/cryptsetup-util.h +++ b/src/shared/cryptsetup-util.h @@ -50,8 +50,8 @@ static inline int sym_crypt_token_max(_unused_ const char *type) { int dlopen_cryptsetup(void); -DEFINE_TRIVIAL_CLEANUP_FUNC(struct crypt_device *, crypt_free); -DEFINE_TRIVIAL_CLEANUP_FUNC(struct crypt_device *, sym_crypt_free); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct crypt_device *, crypt_free, NULL); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct crypt_device *, sym_crypt_free, NULL); void cryptsetup_enable_logging(struct crypt_device *cd); diff --git a/src/shared/firewall-util-iptables.c b/src/shared/firewall-util-iptables.c index fec3000e75..982c61d8fb 100644 --- a/src/shared/firewall-util-iptables.c +++ b/src/shared/firewall-util-iptables.c @@ -27,7 +27,7 @@ #include "macro.h" #include "socket-util.h" -DEFINE_TRIVIAL_CLEANUP_FUNC(struct xtc_handle*, iptc_free); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct xtc_handle*, iptc_free, NULL); static int entry_fill_basics( struct ipt_entry *entry, diff --git a/src/shared/libmount-util.h b/src/shared/libmount-util.h index db9728c332..cf19c56ed1 100644 --- a/src/shared/libmount-util.h +++ b/src/shared/libmount-util.h @@ -8,8 +8,8 @@ #include "macro.h" -DEFINE_TRIVIAL_CLEANUP_FUNC(struct libmnt_table*, mnt_free_table); -DEFINE_TRIVIAL_CLEANUP_FUNC(struct libmnt_iter*, mnt_free_iter); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct libmnt_table*, mnt_free_table, NULL); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct libmnt_iter*, mnt_free_iter, NULL); static inline int libmount_parse( const char *path, diff --git a/src/shared/module-util.h b/src/shared/module-util.h index 4db8c5f04e..8ca6a06a07 100644 --- a/src/shared/module-util.h +++ b/src/shared/module-util.h @@ -7,6 +7,6 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(struct kmod_ctx*, kmod_unref); DEFINE_TRIVIAL_CLEANUP_FUNC(struct kmod_module*, kmod_module_unref); -DEFINE_TRIVIAL_CLEANUP_FUNC(struct kmod_list*, kmod_module_unref_list); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct kmod_list*, kmod_module_unref_list, NULL); int module_load_and_warn(struct kmod_ctx *ctx, const char *module, bool verbose); diff --git a/src/shared/mount-util.h b/src/shared/mount-util.h index 849c37e85b..7183897686 100644 --- a/src/shared/mount-util.h +++ b/src/shared/mount-util.h @@ -45,7 +45,7 @@ int bind_remount_one_with_mountinfo(const char *path, unsigned long new_flags, u int mount_move_root(const char *path); -DEFINE_TRIVIAL_CLEANUP_FUNC(FILE*, endmntent); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(FILE*, endmntent, NULL); #define _cleanup_endmntent_ _cleanup_(endmntentp) int mount_verbose_full( diff --git a/src/shared/openssl-util.h b/src/shared/openssl-util.h index b753a690ba..0f527e74c4 100644 --- a/src/shared/openssl-util.h +++ b/src/shared/openssl-util.h @@ -6,10 +6,10 @@ #if HAVE_OPENSSL # include -DEFINE_TRIVIAL_CLEANUP_FUNC(X509*, X509_free); -DEFINE_TRIVIAL_CLEANUP_FUNC(X509_NAME*, X509_NAME_free); -DEFINE_TRIVIAL_CLEANUP_FUNC(EVP_PKEY_CTX*, EVP_PKEY_CTX_free); -DEFINE_TRIVIAL_CLEANUP_FUNC(EVP_CIPHER_CTX*, EVP_CIPHER_CTX_free); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(X509*, X509_free, NULL); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(X509_NAME*, X509_NAME_free, NULL); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(EVP_PKEY_CTX*, EVP_PKEY_CTX_free, NULL); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(EVP_CIPHER_CTX*, EVP_CIPHER_CTX_free, NULL); int rsa_encrypt_bytes(EVP_PKEY *pkey, const void *decrypted_key, size_t decrypted_key_size, void **ret_encrypt_key, size_t *ret_encrypt_key_size); diff --git a/src/shared/pkcs11-util.h b/src/shared/pkcs11-util.h index 3fa2505deb..f32ab30429 100644 --- a/src/shared/pkcs11-util.h +++ b/src/shared/pkcs11-util.h @@ -21,8 +21,8 @@ P11KitUri *uri_from_module_info(const CK_INFO *info); P11KitUri *uri_from_slot_info(const CK_SLOT_INFO *slot_info); P11KitUri *uri_from_token_info(const CK_TOKEN_INFO *token_info); -DEFINE_TRIVIAL_CLEANUP_FUNC(P11KitUri*, p11_kit_uri_free); -DEFINE_TRIVIAL_CLEANUP_FUNC(CK_FUNCTION_LIST**, p11_kit_modules_finalize_and_release); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(P11KitUri*, p11_kit_uri_free, NULL); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(CK_FUNCTION_LIST**, p11_kit_modules_finalize_and_release, NULL); CK_RV pkcs11_get_slot_list_malloc(CK_FUNCTION_LIST *m, CK_SLOT_ID **ret_slotids, CK_ULONG *ret_n_slotids); diff --git a/src/shared/pwquality-util.h b/src/shared/pwquality-util.h index de288bb017..877f439d11 100644 --- a/src/shared/pwquality-util.h +++ b/src/shared/pwquality-util.h @@ -19,7 +19,7 @@ extern const char* (*sym_pwquality_strerror)(char *buf, size_t len, int errcode, int dlopen_pwquality(void); -DEFINE_TRIVIAL_CLEANUP_FUNC(pwquality_settings_t*, sym_pwquality_free_settings); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(pwquality_settings_t*, sym_pwquality_free_settings, NULL); void pwq_maybe_disable_dictionary(pwquality_settings_t *pwq); int pwq_allocate_context(pwquality_settings_t **ret); diff --git a/src/shared/seccomp-util.h b/src/shared/seccomp-util.h index ee6f7b878b..b3d25c9f3f 100644 --- a/src/shared/seccomp-util.h +++ b/src/shared/seccomp-util.h @@ -121,7 +121,7 @@ extern uint32_t seccomp_local_archs[]; #define ERRNO_IS_SECCOMP_FATAL(r) \ IN_SET(abs(r), EPERM, EACCES, ENOMEM, EFAULT) -DEFINE_TRIVIAL_CLEANUP_FUNC(scmp_filter_ctx, seccomp_release); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(scmp_filter_ctx, seccomp_release, NULL); int parse_syscall_archs(char **l, Set **ret_archs); diff --git a/src/udev/udev-ctrl.c b/src/udev/udev-ctrl.c index 61090a6e4a..3d56354719 100644 --- a/src/udev/udev-ctrl.c +++ b/src/udev/udev-ctrl.c @@ -167,7 +167,7 @@ static void udev_ctrl_disconnect_and_listen_again(struct udev_ctrl *uctrl) { /* We don't return NULL here because uctrl is not freed */ } -DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_ctrl *, udev_ctrl_disconnect_and_listen_again); +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct udev_ctrl*, udev_ctrl_disconnect_and_listen_again, NULL); static int udev_ctrl_connection_event_handler(sd_event_source *s, int fd, uint32_t revents, void *userdata) { _cleanup_(udev_ctrl_disconnect_and_listen_againp) struct udev_ctrl *uctrl = NULL;