diff options
52 files changed, 154 insertions, 165 deletions
diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index 5ab920f4df..7271adaf5b 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -213,10 +213,10 @@ static int compare_unit_start(const UnitTimes *a, const UnitTimes *b) { return CMP(a->activating, b->activating); } -static void unit_times_free(UnitTimes *t) { - for (UnitTimes *p = t; p->has_data; p++) +static UnitTimes* unit_times_free(UnitTimes *t) { + for (UnitTimes *p = t; p && p->has_data; p++) free(p->name); - free(t); + return mfree(t); } DEFINE_TRIVIAL_CLEANUP_FUNC(UnitTimes *, unit_times_free); @@ -313,9 +313,9 @@ finish: return 0; } -static void free_host_info(HostInfo *hi) { +static HostInfo* free_host_info(HostInfo *hi) { if (!hi) - return; + return NULL; free(hi->hostname); free(hi->kernel_name); @@ -324,7 +324,7 @@ static void free_host_info(HostInfo *hi) { free(hi->os_pretty_name); free(hi->virtualization); free(hi->architecture); - free(hi); + return mfree(hi); } DEFINE_TRIVIAL_CLEANUP_FUNC(HostInfo *, free_host_info); @@ -429,7 +429,7 @@ static int acquire_host_info(sd_bus *bus, HostInfo **hi) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_(sd_bus_flush_close_unrefp) sd_bus *system_bus = NULL; - _cleanup_(free_host_infop) HostInfo *host; + _cleanup_(free_host_infop) HostInfo *host = NULL; int r; host = new0(HostInfo, 1); diff --git a/src/basic/strbuf.c b/src/basic/strbuf.c index aee6647e35..535ac58bed 100644 --- a/src/basic/strbuf.c +++ b/src/basic/strbuf.c @@ -26,7 +26,7 @@ * ... */ -struct strbuf *strbuf_new(void) { +struct strbuf* strbuf_new(void) { struct strbuf *str; str = new(struct strbuf, 1); @@ -65,13 +65,13 @@ void strbuf_complete(struct strbuf *str) { } /* clean up everything */ -void strbuf_cleanup(struct strbuf *str) { +struct strbuf* strbuf_cleanup(struct strbuf *str) { if (!str) - return; + return NULL; strbuf_complete(str); free(str->buf); - free(str); + return mfree(str); } static int strbuf_children_cmp(const struct strbuf_child_entry *n1, diff --git a/src/basic/strbuf.h b/src/basic/strbuf.h index 82758d721b..9a21438d64 100644 --- a/src/basic/strbuf.h +++ b/src/basic/strbuf.h @@ -32,8 +32,8 @@ struct strbuf_child_entry { struct strbuf_node *child; }; -struct strbuf *strbuf_new(void); +struct strbuf* strbuf_new(void); ssize_t strbuf_add_string(struct strbuf *str, const char *s, size_t len); void strbuf_complete(struct strbuf *str); -void strbuf_cleanup(struct strbuf *str); +struct strbuf* strbuf_cleanup(struct strbuf *str); DEFINE_TRIVIAL_CLEANUP_FUNC(struct strbuf*, strbuf_cleanup); diff --git a/src/busctl/busctl.c b/src/busctl/busctl.c index 142aba0b92..fde9240749 100644 --- a/src/busctl/busctl.c +++ b/src/busctl/busctl.c @@ -780,24 +780,22 @@ static int member_compare_funcp(Member * const *a, Member * const *b) { return member_compare_func(*a, *b); } -static void member_free(Member *m) { +static Member* member_free(Member *m) { if (!m) - return; + return NULL; free(m->interface); free(m->name); free(m->signature); free(m->result); free(m->value); - free(m); + return mfree(m); } - DEFINE_TRIVIAL_CLEANUP_FUNC(Member*, member_free); -static void member_set_free(Set *s) { - set_free_with_destructor(s, member_free); +static Set* member_set_free(Set *s) { + return set_free_with_destructor(s, member_free); } - DEFINE_TRIVIAL_CLEANUP_FUNC(Set*, member_set_free); static int on_interface(const char *interface, uint64_t flags, void *userdata) { diff --git a/src/core/automount.c b/src/core/automount.c index 5076b351f5..f0fa5c8ca9 100644 --- a/src/core/automount.c +++ b/src/core/automount.c @@ -48,13 +48,13 @@ struct expire_data { int ioctl_fd; }; -static void expire_data_free(struct expire_data *data) { +static struct expire_data* expire_data_free(struct expire_data *data) { if (!data) - return; + return NULL; safe_close(data->dev_autofs_fd); safe_close(data->ioctl_fd); - free(data); + return mfree(data); } DEFINE_TRIVIAL_CLEANUP_FUNC(struct expire_data*, expire_data_free); diff --git a/src/core/namespace.h b/src/core/namespace.h index a4287869f7..54d4985f80 100644 --- a/src/core/namespace.h +++ b/src/core/namespace.h @@ -137,11 +137,11 @@ int setup_namespace( #define RUN_SYSTEMD_EMPTY "/run/systemd/empty" -static inline void namespace_cleanup_tmpdir(char *p) { +static inline char* namespace_cleanup_tmpdir(char *p) { PROTECT_ERRNO; if (!streq_ptr(p, RUN_SYSTEMD_EMPTY)) (void) rmdir(p); - free(p); + return mfree(p); } DEFINE_TRIVIAL_CLEANUP_FUNC(char*, namespace_cleanup_tmpdir); diff --git a/src/core/socket.c b/src/core/socket.c index cb5316af3a..5631054cce 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -969,6 +969,8 @@ static void socket_close_fds(Socket *s) { if (s->remove_on_stop) STRV_FOREACH(i, s->symlinks) (void) unlink(*i); + + /* Note that we don't return NULL here, since s has not been freed. */ } static void socket_apply_socket_options(Socket *s, SocketPort *p, int fd) { @@ -1611,8 +1613,8 @@ static int socket_address_listen_in_cgroup( DEFINE_TRIVIAL_CLEANUP_FUNC(Socket *, socket_close_fds); -static int socket_open_fds(Socket *_s) { - _cleanup_(socket_close_fdsp) Socket *s = _s; +static int socket_open_fds(Socket *orig_s) { + _cleanup_(socket_close_fdsp) Socket *s = orig_s; _cleanup_(mac_selinux_freep) char *label = NULL; bool know_label = false; SocketPort *p; diff --git a/src/core/unit.c b/src/core/unit.c index 3452712590..e9c22375dd 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -82,7 +82,7 @@ const UnitVTable * const unit_vtable[_UNIT_TYPE_MAX] = { static void maybe_warn_about_dependency(Unit *u, const char *other, UnitDependency dependency); -Unit *unit_new(Manager *m, size_t size) { +Unit* unit_new(Manager *m, size_t size) { Unit *u; assert(m); @@ -607,11 +607,11 @@ static void unit_done(Unit *u) { cgroup_context_done(cc); } -void unit_free(Unit *u) { +Unit* unit_free(Unit *u) { char *t; if (!u) - return; + return NULL; u->transient_file = safe_fclose(u->transient_file); @@ -741,7 +741,7 @@ void unit_free(Unit *u) { set_free_free(u->aliases); free(u->id); - free(u); + return mfree(u); } FreezerState unit_freezer_state(Unit *u) { diff --git a/src/core/unit.h b/src/core/unit.h index 7c13e50878..6d38e66680 100644 --- a/src/core/unit.h +++ b/src/core/unit.h @@ -674,8 +674,8 @@ static inline Unit* UNIT_TRIGGER(Unit *u) { return hashmap_first_key(u->dependencies[UNIT_TRIGGERS]); } -Unit *unit_new(Manager *m, size_t size); -void unit_free(Unit *u); +Unit* unit_new(Manager *m, size_t size); +Unit* unit_free(Unit *u); DEFINE_TRIVIAL_CLEANUP_FUNC(Unit *, unit_free); int unit_new_for_name(Manager *m, size_t size, const char *name, Unit **ret); diff --git a/src/coredump/coredump-vacuum.c b/src/coredump/coredump-vacuum.c index 2b0a2e5250..d20df847e8 100644 --- a/src/coredump/coredump-vacuum.c +++ b/src/coredump/coredump-vacuum.c @@ -28,17 +28,17 @@ typedef struct VacuumCandidate { usec_t oldest_mtime; } VacuumCandidate; -static void vacuum_candidate_free(VacuumCandidate *c) { +static VacuumCandidate* vacuum_candidate_free(VacuumCandidate *c) { if (!c) - return; + return NULL; free(c->oldest_file); - free(c); + return mfree(c); } DEFINE_TRIVIAL_CLEANUP_FUNC(VacuumCandidate*, vacuum_candidate_free); -static void vacuum_candidate_hashmap_free(Hashmap *h) { - hashmap_free_with_destructor(h, vacuum_candidate_free); +static Hashmap* vacuum_candidate_hashmap_free(Hashmap *h) { + return hashmap_free_with_destructor(h, vacuum_candidate_free); } DEFINE_TRIVIAL_CLEANUP_FUNC(Hashmap*, vacuum_candidate_hashmap_free); diff --git a/src/initctl/initctl.c b/src/initctl/initctl.c index d818f452f7..c48fef16ef 100644 --- a/src/initctl/initctl.c +++ b/src/initctl/initctl.c @@ -210,8 +210,9 @@ static int fifo_process(Fifo *f) { return 0; } -static void fifo_free(Fifo *f) { - assert(f); +static Fifo* fifo_free(Fifo *f) { + if (!f) + return NULL; if (f->server) { assert(f->server->n_fifos > 0); @@ -226,7 +227,7 @@ static void fifo_free(Fifo *f) { safe_close(f->fd); } - free(f); + return mfree(f); } DEFINE_TRIVIAL_CLEANUP_FUNC(Fifo*, fifo_free); diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c index 1c3652bf5b..73b3240677 100644 --- a/src/journal/journald-stream.c +++ b/src/journal/journald-stream.c @@ -98,9 +98,9 @@ struct StdoutStream { char id_field[STRLEN("_STREAM_ID=") + SD_ID128_STRING_MAX]; }; -void stdout_stream_free(StdoutStream *s) { +StdoutStream* stdout_stream_free(StdoutStream *s) { if (!s) - return; + return NULL; if (s->server) { @@ -129,7 +129,7 @@ void stdout_stream_free(StdoutStream *s) { free(s->state_file); free(s->buffer); - free(s); + return mfree(s); } DEFINE_TRIVIAL_CLEANUP_FUNC(StdoutStream*, stdout_stream_free); diff --git a/src/journal/journald-stream.h b/src/journal/journald-stream.h index 0a033b4dce..7b756c05ec 100644 --- a/src/journal/journald-stream.h +++ b/src/journal/journald-stream.h @@ -9,7 +9,7 @@ typedef struct StdoutStream StdoutStream; int server_open_stdout_socket(Server *s, const char *stdout_socket); int server_restore_streams(Server *s, FDSet *fds); -void stdout_stream_free(StdoutStream *s); +StdoutStream* stdout_stream_free(StdoutStream *s); int stdout_stream_install(Server *s, int fd, StdoutStream **ret); void stdout_stream_destroy(StdoutStream *s); void stdout_stream_send_notify(StdoutStream *s); diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c index 80292befeb..bc50664dc7 100644 --- a/src/libsystemd-network/sd-dhcp-server.c +++ b/src/libsystemd-network/sd-dhcp-server.c @@ -649,12 +649,12 @@ static int parse_request(uint8_t code, uint8_t len, const void *option, void *us return 0; } -static void dhcp_request_free(DHCPRequest *req) { +static DHCPRequest* dhcp_request_free(DHCPRequest *req) { if (!req) - return; + return NULL; free(req->client_id.data); - free(req); + return mfree(req); } DEFINE_TRIVIAL_CLEANUP_FUNC(DHCPRequest*, dhcp_request_free); diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c index 8abbefcf27..d9991cfe19 100644 --- a/src/libsystemd/sd-event/sd-event.c +++ b/src/libsystemd/sd-event/sd-event.c @@ -939,7 +939,7 @@ static void source_disconnect(sd_event_source *s) { sd_event_unref(event); } -static void source_free(sd_event_source *s) { +static sd_event_source* source_free(sd_event_source *s) { assert(s); source_disconnect(s); @@ -989,7 +989,7 @@ static void source_free(sd_event_source *s) { s->destroy_callback(s->userdata); free(s->description); - free(s); + return mfree(s); } DEFINE_TRIVIAL_CLEANUP_FUNC(sd_event_source*, source_free); diff --git a/src/libsystemd/sd-hwdb/hwdb-util.c b/src/libsystemd/sd-hwdb/hwdb-util.c index 4c94ba9c88..34be0e7fcc 100644 --- a/src/libsystemd/sd-hwdb/hwdb-util.c +++ b/src/libsystemd/sd-hwdb/hwdb-util.c @@ -115,13 +115,13 @@ static void trie_node_cleanup(struct trie_node *node) { free(node); } -static void trie_free(struct trie *trie) { +static struct trie* trie_free(struct trie *trie) { if (!trie) - return; + return NULL; trie_node_cleanup(trie->root); strbuf_cleanup(trie->strings); - free(trie); + return mfree(trie); } DEFINE_TRIVIAL_CLEANUP_FUNC(struct trie*, trie_free); diff --git a/src/login/logind-brightness.c b/src/login/logind-brightness.c index f4306749ec..5eb3534f53 100644 --- a/src/login/logind-brightness.c +++ b/src/login/logind-brightness.c @@ -44,9 +44,9 @@ typedef struct BrightnessWriter { sd_event_source* child_event_source; } BrightnessWriter; -static void brightness_writer_free(BrightnessWriter *w) { +static BrightnessWriter* brightness_writer_free(BrightnessWriter *w) { if (!w) - return; + return NULL; if (w->manager && w->path) (void) hashmap_remove_value(w->manager->brightness_writers, w->path, w); @@ -59,7 +59,7 @@ static void brightness_writer_free(BrightnessWriter *w) { w->child_event_source = sd_event_source_unref(w->child_event_source); - free(w); + return mfree(w); } DEFINE_TRIVIAL_CLEANUP_FUNC(BrightnessWriter*, brightness_writer_free); diff --git a/src/network/netdev/l2tp-tunnel.c b/src/network/netdev/l2tp-tunnel.c index e302a2cf3b..a909b15764 100644 --- a/src/network/netdev/l2tp-tunnel.c +++ b/src/network/netdev/l2tp-tunnel.c @@ -39,18 +39,16 @@ static const char* const l2tp_local_address_type_table[_NETDEV_L2TP_LOCAL_ADDRES DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(l2tp_local_address_type, L2tpLocalAddressType); -static void l2tp_session_free(L2tpSession *s) { +static L2tpSession* l2tp_session_free(L2tpSession *s) { if (!s) - return; + return NULL; if (s->tunnel && s->section) ordered_hashmap_remove(s->tunnel->sessions_by_section, s->section); network_config_section_free(s->section); - free(s->name); - - free(s); + return mfree(s); } DEFINE_NETWORK_SECTION_FUNCTIONS(L2tpSession, l2tp_session_free); diff --git a/src/network/netdev/macsec.c b/src/network/netdev/macsec.c index bef5ba1c51..77c5f8c4e7 100644 --- a/src/network/netdev/macsec.c +++ b/src/network/netdev/macsec.c @@ -35,9 +35,9 @@ static void security_association_init(SecurityAssociation *sa) { sa->use_for_encoding = -1; } -static void macsec_receive_association_free(ReceiveAssociation *c) { +static ReceiveAssociation* macsec_receive_association_free(ReceiveAssociation *c) { if (!c) - return; + return NULL; if (c->macsec && c->section) ordered_hashmap_remove(c->macsec->receive_associations_by_section, c->section); @@ -45,7 +45,7 @@ static void macsec_receive_association_free(ReceiveAssociation *c) { network_config_section_free(c->section); security_association_clear(&c->sa); - free(c); + return mfree(c); } DEFINE_NETWORK_SECTION_FUNCTIONS(ReceiveAssociation, macsec_receive_association_free); @@ -90,9 +90,9 @@ static int macsec_receive_association_new_static(MACsec *s, const char *filename return 0; } -static void macsec_receive_channel_free(ReceiveChannel *c) { +static ReceiveChannel* macsec_receive_channel_free(ReceiveChannel *c) { if (!c) - return; + return NULL; if (c->macsec) { if (c->sci.as_uint64 > 0) @@ -104,7 +104,7 @@ static void macsec_receive_channel_free(ReceiveChannel *c) { network_config_section_free(c->section); - free(c); + return mfree(c); } DEFINE_NETWORK_SECTION_FUNCTIONS(ReceiveChannel, macsec_receive_channel_free); @@ -162,9 +162,9 @@ static int macsec_receive_channel_new_static(MACsec *s, const char *filename, un return 0; } -static void macsec_transmit_association_free(TransmitAssociation *a) { +static TransmitAssociation* macsec_transmit_association_free(TransmitAssociation *a) { if (!a) - return; + return NULL; if (a->macsec && a->section) ordered_hashmap_remove(a->macsec->transmit_associations_by_section, a->section); @@ -172,7 +172,7 @@ static void macsec_transmit_association_free(TransmitAssociation *a) { network_config_section_free(a->section); security_association_clear(&a->sa); - free(a); + return mfree(a); } DEFINE_NETWORK_SECTION_FUNCTIONS(TransmitAssociation, macsec_transmit_association_free); diff --git a/src/network/netdev/wireguard.c b/src/network/netdev/wireguard.c index e442ecc266..75d6d376a5 100644 --- a/src/network/netdev/wireguard.c +++ b/src/network/netdev/wireguard.c @@ -26,11 +26,11 @@ static void resolve_endpoints(NetDev *netdev); -static void wireguard_peer_free(WireguardPeer *peer) { +static WireguardPeer* wireguard_peer_free(WireguardPeer *peer) { WireguardIPmask *mask; if (!peer) - return; + return NULL; if (peer->wireguard) { LIST_REMOVE(peers, peer->wireguard->peers, peer); @@ -54,7 +54,7 @@ static void wireguard_peer_free(WireguardPeer *peer) { free(peer->preshared_key_file); explicit_bzero_safe(peer->preshared_key, WG_KEY_LEN); - free(peer); + return mfree(peer); } DEFINE_NETWORK_SECTION_FUNCTIONS(WireguardPeer, wireguard_peer_free); diff --git a/src/network/networkctl.c b/src/network/networkctl.c index 4381f63a2d..1dd3438abd 100644 --- a/src/network/networkctl.c +++ b/src/network/networkctl.c @@ -230,7 +230,7 @@ static int link_info_compare(const LinkInfo *a, const LinkInfo *b) { return CMP(a->ifindex, b->ifindex); } -static const LinkInfo* link_info_array_free(LinkInfo *array) { +static LinkInfo* link_info_array_free(LinkInfo *array) { for (unsigned i = 0; array && array[i].needs_freeing; i++) { sd_device_unref(array[i].sd_device); free(array[i].ssid); diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c index d7e0662453..debd9f1ecc 100644 --- a/src/network/networkd-manager.c +++ b/src/network/networkd-manager.c @@ -850,11 +850,11 @@ int manager_new(Manager **ret) { return 0; } -void manager_free(Manager *m) { +Manager* manager_free(Manager *m) { Link *link; if (!m) - return; + return NULL; free(m->state_file); @@ -909,7 +909,7 @@ void manager_free(Manager *m) { m->fw_ctx = fw_ctx_free(m->fw_ctx); - free(m); + return mfree(m); } int manager_start(Manager *m) { diff --git a/src/network/networkd-manager.h b/src/network/networkd-manager.h index f553abcc54..8b5f8a9dc0 100644 --- a/src/network/networkd-manager.h +++ b/src/network/networkd-manager.h @@ -83,7 +83,7 @@ struct Manager { }; int manager_new(Manager **ret); -void manager_free(Manager *m); +Manager* manager_free(Manager *m); int manager_connect_bus(Manager *m); int manager_start(Manager *m); diff --git a/src/network/networkd-util.h b/src/network/networkd-util.h index efeeb86eb0..1736e2b57b 100644 --- a/src/network/networkd-util.h +++ b/src/network/networkd-util.h @@ -47,8 +47,8 @@ sd_dhcp_lease_server_type dhcp_lease_server_type_from_string(const char *s) _pur int kernel_route_expiration_supported(void); -static inline void network_config_section_free(NetworkConfigSection *cs) { - free(cs); +static inline NetworkConfigSection* network_config_section_free(NetworkConfigSection *cs) { + return mfree(cs); } DEFINE_TRIVIAL_CLEANUP_FUNC(NetworkConfigSection*, network_config_section_free); @@ -66,13 +66,14 @@ static inline bool section_is_invalid(NetworkConfigSection *section) { } #define DEFINE_NETWORK_SECTION_FUNCTIONS(type, free_func) \ - static inline void free_func##_or_set_invalid(type *p) { \ + static inline type* free_func##_or_set_invalid(type *p) { \ assert(p); \ \ if (p->section) \ p->section->invalid = true; \ else \ free_func(p); \ + return NULL; \ } \ DEFINE_TRIVIAL_CLEANUP_FUNC(type*, free_func); \ DEFINE_TRIVIAL_CLEANUP_FUNC(type*, free_func##_or_set_invalid); diff --git a/src/network/tc/qdisc.c b/src/network/tc/qdisc.c index 7016dc1877..2e0f0a12eb 100644 --- a/src/network/tc/qdisc.c +++ b/src/network/tc/qdisc.c @@ -134,9 +134,9 @@ int qdisc_new_static(QDiscKind kind, Network *network, const char *filename, uns return 0; } -void qdisc_free(QDisc *qdisc) { +QDisc* qdisc_free(QDisc *qdisc) { if (!qdisc) - return; + return NULL; if (qdisc->network && qdisc->section) ordered_hashmap_remove(qdisc->network->tc_by_section, qdisc->section); @@ -144,7 +144,7 @@ void qdisc_free(QDisc *qdisc) { network_config_section_free(qdisc->section); free(qdisc->tca_kind); - free(qdisc); + return mfree(qdisc); } static int qdisc_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) { diff --git a/src/network/tc/qdisc.h b/src/network/tc/qdisc.h index 2232189f4f..bf2df146a7 100644 --- a/src/network/tc/qdisc.h +++ b/src/network/tc/qdisc.h @@ -74,7 +74,7 @@ extern const QDiscVTable * const qdisc_vtable[_QDISC_KIND_MAX]; /* For casting the various qdisc kinds into a qdisc */ #define QDISC(q) (&(q)->meta) -void qdisc_free(QDisc *qdisc); +QDisc* qdisc_free(QDisc *qdisc); int qdisc_new_static(QDiscKind kind, Network *network, const char *filename, unsigned section_line, QDisc **ret); int qdisc_configure(Link *link, QDisc *qdisc); diff --git a/src/network/tc/tclass.c b/src/network/tc/tclass.c index 64bdfbb90b..d8145997f0 100644 --- a/src/network/tc/tclass.c +++ b/src/network/tc/tclass.c @@ -90,16 +90,16 @@ int tclass_new_static(TClassKind kind, Network *network, const char *filename, u return 0; } -void tclass_free(TClass *tclass) { +TClass* tclass_free(TClass *tclass) { if (!tclass) - return; + return NULL; if (tclass->network && tclass->section) ordered_hashmap_remove(tclass->network->tc_by_section, tclass->section); network_config_section_free(tclass->section); - free(tclass); + return mfree(tclass); } static int tclass_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) { diff --git a/src/network/tc/tclass.h b/src/network/tc/tclass.h index 8e5e52c401..fc91789f30 100644 --- a/src/network/tc/tclass.h +++ b/src/network/tc/tclass.h @@ -53,7 +53,7 @@ extern const TClassVTable * const tclass_vtable[_TCLASS_KIND_MAX]; /* For casting the various tclass kinds into a tclass */ #define TCLASS(t) (&(t)->meta) -void tclass_free(TClass *tclass); +TClass* tclass_free(TClass *tclass); int tclass_new_static(TClassKind kind, Network *network, const char *filename, unsigned section_line, TClass **ret); int tclass_configure(Link *link, TClass *tclass); diff --git a/src/network/wait-online/manager.c b/src/network/wait-online/manager.c index 8321395550..f6c8cf909f 100644 --- a/src/network/wait-online/manager.c +++ b/src/network/wait-online/manager.c @@ -347,21 +347,18 @@ int manager_new(Manager **ret, Hashmap *interfaces, char **ignore, return 0; } -void manager_free(Manager *m) { +Manager* manager_free(Manager *m) { if (!m) - return; + return NULL; hashmap_free_with_destructor(m->links, link_free); hashmap_free(m->links_by_name); sd_event_source_unref(m->network_monitor_event_source); sd_network_monitor_unref(m->network_monitor); - sd_event_source_unref(m->rtnl_event_source); sd_netlink_unref(m->rtnl); - sd_event_unref(m->event); - free(m); - return; + return mfree(m); } diff --git a/src/network/wait-online/manager.h b/src/network/wait-online/manager.h index f5e83532ae..9892a43dc9 100644 --- a/src/network/wait-online/manager.h +++ b/src/network/wait-online/manager.h @@ -32,7 +32,7 @@ struct Manager { sd_event *event; }; -void manager_free(Manager *m); +Manager* manager_free(Manager *m); int manager_new(Manager **ret, Hashmap *interfaces, char **ignore, LinkOperationalStateRange required_operstate, bool any, usec_t timeout); diff --git a/src/oom/oomd-manager.c b/src/oom/oomd-manager.c index 94b17dd07b..bdf41807b2 100644 --- a/src/oom/oomd-manager.c +++ b/src/oom/oomd-manager.c @@ -397,7 +397,7 @@ static int monitor_cgroup_contexts(Manager *m) { return 0; } -void manager_free(Manager *m) { +Manager* manager_free(Manager *m) { assert(m); varlink_close_unref(m->varlink); @@ -410,7 +410,7 @@ void manager_free(Manager *m) { hashmap_free(m->monitored_swap_cgroup_contexts); hashmap_free(m->monitored_mem_pressure_cgroup_contexts); - free(m); + return mfree(m); } int manager_new(Manager **ret) { diff --git a/src/oom/oomd-manager.h b/src/oom/oomd-manager.h index 521665e0a8..50f10021c7 100644 --- a/src/oom/oomd-manager.h +++ b/src/oom/oomd-manager.h @@ -51,7 +51,7 @@ struct Manager { Varlink *varlink; }; -void manager_free(Manager *m); +Manager* manager_free(Manager *m); DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free); int manager_new(Manager **ret); diff --git a/src/resolve/resolved-dns-cache.c b/src/resolve/resolved-dns-cache.c index cf0e221621..03da73c4ae 100644 --- a/src/resolve/resolved-dns-cache.c +++ b/src/resolve/resolved-dns-cache.c @@ -80,17 +80,16 @@ static const char *dns_cache_item_type_to_string(DnsCacheItem *item) { return NULL; } -static void dns_cache_item_free(DnsCacheItem *i) { +static DnsCacheItem* dns_cache_item_free(DnsCacheItem *i) { if (!i) - return; + return NULL; dns_resource_record_unref(i->rr); dns_resource_key_unref(i->key); dns_answer_unref(i->answer); dns_packet_unref(i->full_packet); - free(i); + return mfree(i); } - DEFINE_TRIVIAL_CLEANUP_FUNC(DnsCacheItem*, dns_cache_item_free); static void dns_cache_item_unlink_and_free(DnsCache *c, DnsCacheItem *i) { diff --git a/src/resolve/resolved-dns-zone.c b/src/resolve/resolved-dns-zone.c index 4c5e1fe372..6f15c53953 100644 --- a/src/resolve/resolved-dns-zone.c +++ b/src/resolve/resolved-dns-zone.c @@ -26,16 +26,15 @@ void dns_zone_item_probe_stop(DnsZoneItem *i) { dns_transaction_gc(t); } -static void dns_zone_item_free(DnsZoneItem *i) { +static DnsZoneItem* dns_zone_item_free(DnsZoneItem *i) { if (!i) - return; + return NULL; dns_zone_item_probe_stop(i); dns_resource_record_unref(i->rr); - free(i); + return mfree(i); } - DEFINE_TRIVIAL_CLEANUP_FUNC(DnsZoneItem*, dns_zone_item_free); static void dns_zone_item_remove_and_free(DnsZone *z, DnsZoneItem *i) { diff --git a/src/shared/barrier.c b/src/shared/barrier.c index 9c93d61a3c..271bba8cde 100644 --- a/src/shared/barrier.c +++ b/src/shared/barrier.c @@ -123,14 +123,15 @@ int barrier_create(Barrier *b) { * * If @b is NULL, this is a no-op. */ -void barrier_destroy(Barrier *b) { +Barrier* barrier_destroy(Barrier *b) { if (!b) - return; + return NULL; b->me = safe_close(b->me); b->them = safe_close(b->them); safe_close_pair(b->pipe); b->barriers = 0; + return NULL; } /** diff --git a/src/shared/barrier.h b/src/shared/barrier.h index b11dce4fc0..b9fc92d752 100644 --- a/src/shared/barrier.h +++ b/src/shared/barrier.h @@ -37,7 +37,7 @@ struct Barrier { #define BARRIER_NULL {-1, -1, {-1, -1}, 0} int barrier_create(Barrier *obj); -void barrier_destroy(Barrier *b); +Barrier* barrier_destroy(Barrier *b); DEFINE_TRIVIAL_CLEANUP_FUNC(Barrier*, barrier_destroy); diff --git a/src/shared/bitmap.c b/src/shared/bitmap.c index 5d450c8832..33528388f0 100644 --- a/src/shared/bitmap.c +++ b/src/shared/bitmap.c @@ -24,11 +24,11 @@ #define BITMAP_NUM_TO_REM(n) ((n) % (sizeof(uint64_t) * 8)) #define BITMAP_OFFSET_TO_NUM(offset, rem) ((offset) * sizeof(uint64_t) * 8 + (rem)) -Bitmap *bitmap_new(void) { +Bitmap* bitmap_new(void) { return new0(Bitmap, 1); } -Bitmap *bitmap_copy(Bitmap *b) { +Bitmap* bitmap_copy(Bitmap *b) { Bitmap *ret; ret = bitmap_new(); @@ -43,12 +43,12 @@ Bitmap *bitmap_copy(Bitmap *b) { return ret; } -void bitmap_free(Bitmap *b) { +Bitmap* bitmap_free(Bitmap *b) { if (!b) - return; + return NULL; free(b->bitmaps); - free(b); + return mfree(b); } int bitmap_ensure_allocated(Bitmap **b) { diff --git a/src/shared/bitmap.h b/src/shared/bitmap.h index 1c305a2c41..5c7651c68d 100644 --- a/src/shared/bitmap.h +++ b/src/shared/bitmap.h @@ -12,10 +12,10 @@ typedef struct Bitmap { size_t bitmaps_allocated; } Bitmap; -Bitmap *bitmap_new(void); -Bitmap *bitmap_copy(Bitmap *b); +Bitmap* bitmap_new(void); +Bitmap* bitmap_copy(Bitmap *b); int bitmap_ensure_allocated(Bitmap **b); -void bitmap_free(Bitmap *b); +Bitmap* bitmap_free(Bitmap *b); int bitmap_set(Bitmap *b, unsigned n); void bitmap_unset(Bitmap *b, unsigned n); diff --git a/src/shared/bus-wait-for-jobs.c b/src/shared/bus-wait-for-jobs.c index 005294c33a..80f7785323 100644 --- a/src/shared/bus-wait-for-jobs.c +++ b/src/shared/bus-wait-for-jobs.c @@ -61,9 +61,9 @@ static int match_job_removed(sd_bus_message *m, void *userdata, sd_bus_error *er return 0; } -void bus_wait_for_jobs_free(BusWaitForJobs *d) { +BusWaitForJobs* bus_wait_for_jobs_free(BusWaitForJobs *d) { if (!d) - return; + return NULL; set_free(d->jobs); @@ -75,7 +75,7 @@ void bus_wait_for_jobs_free(BusWaitForJobs *d) { free(d->name); free(d->result); - free(d); + return mfree(d); } int bus_wait_for_jobs_new(sd_bus *bus, BusWaitForJobs **ret) { diff --git a/src/shared/bus-wait-for-jobs.h b/src/shared/bus-wait-for-jobs.h index 0155887455..68c9d604ad 100644 --- a/src/shared/bus-wait-for-jobs.h +++ b/src/shared/bus-wait-for-jobs.h @@ -8,7 +8,7 @@ typedef struct BusWaitForJobs BusWaitForJobs; int bus_wait_for_jobs_new(sd_bus *bus, BusWaitForJobs **ret); -void bus_wait_for_jobs_free(BusWaitForJobs *d); +BusWaitForJobs* bus_wait_for_jobs_free(BusWaitForJobs *d); int bus_wait_for_jobs_add(BusWaitForJobs *d, const char *path); int bus_wait_for_jobs(BusWaitForJobs *d, bool quiet, const char* const* extra_args); int bus_wait_for_jobs_one(BusWaitForJobs *d, const char *path, bool quiet); diff --git a/src/shared/calendarspec.c b/src/shared/calendarspec.c index c23a91eeed..4f68a570b5 100644 --- a/src/shared/calendarspec.c +++ b/src/shared/calendarspec.c @@ -33,14 +33,13 @@ /* Let's make sure that the microsecond component is safe to be stored in an 'int' */ assert_cc(INT_MAX >= USEC_PER_SEC); -static void chain_free(CalendarComponent *c) { - CalendarComponent *n; - +static CalendarComponent* chain_free(CalendarComponent *c) { while (c) { - n = c->next; + CalendarComponent *n = c->next; free(c); c = n; } + return NULL; } DEFINE_TRIVIAL_CLEANUP_FUNC(CalendarComponent*, chain_free); diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index de94d3399c..62050daecd 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -1681,12 +1681,12 @@ static int verity_can_reuse( return 0; } -static inline void dm_deferred_remove_clean(char *name) { +static inline char* dm_deferred_remove_clean(char *name) { if (!name) - return; + return NULL; (void) sym_crypt_deactivate_by_name(NULL, name, CRYPT_DEACTIVATE_DEFERRED); - free(name); + return mfree(name); } DEFINE_TRIVIAL_CLEANUP_FUNC(char *, dm_deferred_remove_clean); diff --git a/src/shared/install.c b/src/shared/install.c index e70fa45022..77208582b7 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -3346,12 +3346,12 @@ int unit_file_preset_all( return execute_preset(scope, &plus, &minus, &paths, config_path, NULL, mode, !!(flags & UNIT_FILE_FORCE), changes, n_changes); } -static void unit_file_list_free_one(UnitFileList *f) { +static UnitFileList* unit_file_list_free_one(UnitFileList *f) { if (!f) - return; + return NULL; free(f->path); - free(f); + return mfree(f); } Hashmap* unit_file_list_free(Hashmap *h) { diff --git a/src/systemctl/systemctl-show.c b/src/systemctl/systemctl-show.c index 57e708095d..6f3b3566d7 100644 --- a/src/systemctl/systemctl-show.c +++ b/src/systemctl/systemctl-show.c @@ -147,15 +147,14 @@ typedef struct UnitCondition { LIST_FIELDS(struct UnitCondition, conditions); } UnitCondition; -static void unit_condition_free(UnitCondition *c) { +static UnitCondition* unit_condition_free(UnitCondition *c) { if (!c) - return; + return NULL; free(c->name); free(c->param); - free(c); + return mfree(c); } - DEFINE_TRIVIAL_CLEANUP_FUNC(UnitCondition*, unit_condition_free); typedef struct UnitStatusInfo { diff --git a/src/sysv-generator/sysv-generator.c b/src/sysv-generator/sysv-generator.c index 008a8250bb..8c7aef23c3 100644 --- a/src/sysv-generator/sysv-generator.c +++ b/src/sysv-generator/sysv-generator.c @@ -59,9 +59,9 @@ typedef struct SysvStub { bool loaded; } SysvStub; -static void free_sysvstub(SysvStub *s) { +static SysvStub* free_sysvstub(SysvStub *s) { if (!s) - return; + return NULL; free(s->name); free(s->path); @@ -71,9 +71,8 @@ static void free_sysvstub(SysvStub *s) { strv_free(s->after); strv_free(s->wants); strv_free(s->wanted_by); - free(s); + return mfree(s); } - DEFINE_TRIVIAL_CLEANUP_FUNC(SysvStub*, free_sysvstub); static void free_sysvstub_hashmapp(Hashmap **h) { diff --git a/src/timesync/timesyncd-manager.c b/src/timesync/timesyncd-manager.c index 07fee57391..8c2ee4cbec 100644 --- a/src/timesync/timesyncd-manager.c +++ b/src/timesync/timesyncd-manager.c @@ -915,9 +915,9 @@ void manager_flush_server_names(Manager *m, ServerType t) { server_name_free(m->fallback_servers); } -void manager_free(Manager *m) { +Manager* manager_free(Manager *m) { if (!m) - return; + return NULL; manager_disconnect(m); manager_flush_server_names(m, SERVER_SYSTEM); @@ -934,7 +934,7 @@ void manager_free(Manager *m) { sd_bus_flush_close_unref(m->bus); - free(m); + return mfree(m); } static int manager_network_read_link_servers(Manager *m) { diff --git a/src/timesync/timesyncd-manager.h b/src/timesync/timesyncd-manager.h index 37cf406190..af218a5f63 100644 --- a/src/timesync/timesyncd-manager.h +++ b/src/timesync/timesyncd-manager.h @@ -103,7 +103,7 @@ struct Manager { }; int manager_new(Manager **ret); -void manager_free(Manager *m); +Manager* manager_free(Manager *m); DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free); diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index 9209f8f4b4..f2ca1bb561 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -45,9 +45,9 @@ struct link_config_ctx { usec_t network_dirs_ts_usec; }; -static void link_config_free(link_config *link) { +static link_config* link_config_free(link_config *link) { if (!link) - return; + return NULL; free(link->filename); @@ -62,7 +62,7 @@ static void link_config_free(link_config *link) { free(link->alternative_names_policy); free(link->alias); - free(link); + return mfree(link); } DEFINE_TRIVIAL_CLEANUP_FUNC(link_config*, link_config_free); @@ -77,19 +77,14 @@ static void link_configs_free(link_config_ctx *ctx) { link_config_free(link); } -void link_config_ctx_free(link_config_ctx *ctx) { +link_config_ctx* link_config_ctx_free(link_config_ctx *ctx) { if (!ctx) - return; + return NULL; safe_close(ctx->ethtool_fd); - sd_netlink_unref(ctx->rtnl); - link_configs_free(ctx); - - free(ctx); - - return; + return mfree(ctx); } int link_config_ctx_new(link_config_ctx **ret) { diff --git a/src/udev/net/link-config.h b/src/udev/net/link-config.h index 3f899e9879..71f8983fb7 100644 --- a/src/udev/net/link-config.h +++ b/src/udev/net/link-config.h @@ -69,7 +69,7 @@ struct link_config { }; int link_config_ctx_new(link_config_ctx **ret); -void link_config_ctx_free(link_config_ctx *ctx); +link_config_ctx* link_config_ctx_free(link_config_ctx *ctx); DEFINE_TRIVIAL_CLEANUP_FUNC(link_config_ctx*, link_config_ctx_free); int link_load_one(link_config_ctx *ctx, const char *filename); diff --git a/src/udev/udev-ctrl.c b/src/udev/udev-ctrl.c index c65f8772ea..61090a6e4a 100644 --- a/src/udev/udev-ctrl.c +++ b/src/udev/udev-ctrl.c @@ -164,6 +164,7 @@ static void udev_ctrl_disconnect_and_listen_again(struct udev_ctrl *uctrl) { udev_ctrl_disconnect(uctrl); udev_ctrl_unref(uctrl); (void) sd_event_source_set_enabled(uctrl->event_source, SD_EVENT_ON); + /* We don't return NULL here because uctrl is not freed */ } DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_ctrl *, udev_ctrl_disconnect_and_listen_again); diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index fb4de17a5c..78184b4136 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -264,9 +264,9 @@ static void udev_rule_line_clear_tokens(UdevRuleLine *rule_line) { rule_line->tokens = NULL; } -static void udev_rule_line_free(UdevRuleLine *rule_line) { +static UdevRuleLine* udev_rule_line_free(UdevRuleLine *rule_line) { if (!rule_line) - return; + return NULL; udev_rule_line_clear_tokens(rule_line); @@ -278,7 +278,7 @@ static void udev_rule_line_free(UdevRuleLine *rule_line) { } free(rule_line->line); - free(rule_line); + return mfree(rule_line); } DEFINE_TRIVIAL_CLEANUP_FUNC(UdevRuleLine*, udev_rule_line_free); diff --git a/src/udev/udevd.c b/src/udev/udevd.c index 0134f78b4b..9772246aeb 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -173,9 +173,9 @@ static void event_free(struct event *event) { free(event); } -static void worker_free(struct worker *worker) { +static struct worker* worker_free(struct worker *worker) { if (!worker) - return; + return NULL; assert(worker->manager); @@ -183,7 +183,7 @@ static void worker_free(struct worker *worker) { sd_device_monitor_unref(worker->monitor); event_free(worker->event); - free(worker); + return mfree(worker); } DEFINE_TRIVIAL_CLEANUP_FUNC(struct worker *, worker_free); @@ -287,9 +287,9 @@ static void manager_clear_for_worker(Manager *manager) { manager->worker_watch[READ_END] = safe_close(manager->worker_watch[READ_END]); } -static void manager_free(Manager *manager) { +static Manager* manager_free(Manager *manager) { if (!manager) - return; + return NULL; udev_builtin_exit(); @@ -306,7 +306,7 @@ static void manager_free(Manager *manager) { safe_close(manager->fd_inotify); safe_close_pair(manager->worker_watch); - free(manager); + return mfree(manager); } DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free); |