1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-10 01:17:44 +03:00

tree-wide: return NULL from freeing functions

I started working on this because I wanted to change how
DEFINE_TRIVIAL_CLEANUP_FUNC is defined. Even independently of that change, it's
nice to make make things more consistent and predictable.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2021-02-16 13:48:04 +01:00
parent 5d160a2304
commit 75db809ae5
52 changed files with 154 additions and 165 deletions

View File

@ -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);

View File

@ -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,

View File

@ -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);

View File

@ -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) {

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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) {

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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) {

View File

@ -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);

View File

@ -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);

View File

@ -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) {

View File

@ -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);

View File

@ -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) {

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -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) {

View File

@ -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);

View File

@ -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) {

View File

@ -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) {

View File

@ -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;
}
/**

View File

@ -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);

View File

@ -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) {

View File

@ -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);

View File

@ -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) {

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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) {

View File

@ -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 {

View File

@ -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) {

View File

@ -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) {

View File

@ -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);

View File

@ -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) {

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);