mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-25 23:21:33 +03:00
Merge pull request #4391 from keszybz/treewide-macros
Use mfree more and add another function to simplify a common set&free pattern
This commit is contained in:
commit
a775369354
15
coccinelle/free_and_replace.cocci
Normal file
15
coccinelle/free_and_replace.cocci
Normal file
@ -0,0 +1,15 @@
|
||||
@@
|
||||
expression p, q;
|
||||
@@
|
||||
- free(p);
|
||||
- p = q;
|
||||
- q = NULL;
|
||||
- return 0;
|
||||
+ return free_and_replace(p, q);
|
||||
@@
|
||||
expression p, q;
|
||||
@@
|
||||
- free(p);
|
||||
- p = q;
|
||||
- q = NULL;
|
||||
+ free_and_replace(p, q);
|
6
coccinelle/mfree_return.cocci
Normal file
6
coccinelle/mfree_return.cocci
Normal file
@ -0,0 +1,6 @@
|
||||
@@
|
||||
expression p;
|
||||
@@
|
||||
- free(p);
|
||||
- return NULL;
|
||||
+ return mfree(p);
|
@ -43,6 +43,14 @@ static inline void *mfree(void *memory) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#define free_and_replace(a, b) \
|
||||
({ \
|
||||
free(a); \
|
||||
(a) = (b); \
|
||||
(b) = NULL; \
|
||||
0; \
|
||||
})
|
||||
|
||||
void* memdup(const void *p, size_t l) _alloc_(2);
|
||||
|
||||
static inline void freep(void *p) {
|
||||
|
@ -58,10 +58,8 @@ Bitmap *bitmap_copy(Bitmap *b) {
|
||||
return NULL;
|
||||
|
||||
ret->bitmaps = newdup(uint64_t, b->bitmaps, b->n_bitmaps);
|
||||
if (!ret->bitmaps) {
|
||||
free(ret);
|
||||
return NULL;
|
||||
}
|
||||
if (!ret->bitmaps)
|
||||
return mfree(ret);
|
||||
|
||||
ret->n_bitmaps = ret->bitmaps_allocated = b->n_bitmaps;
|
||||
return ret;
|
||||
|
@ -544,8 +544,7 @@ char *replace_env(const char *format, char **env) {
|
||||
return k;
|
||||
|
||||
fail:
|
||||
free(r);
|
||||
return NULL;
|
||||
return mfree(r);
|
||||
}
|
||||
|
||||
char **replace_env_argv(char **argv, char **env) {
|
||||
|
@ -678,9 +678,7 @@ int chase_symlinks(const char *path, const char *_root, char **ret) {
|
||||
!path_startswith(parent, root))
|
||||
return -EINVAL;
|
||||
|
||||
free(done);
|
||||
done = parent;
|
||||
parent = NULL;
|
||||
free_and_replace(done, parent);
|
||||
|
||||
fd_parent = openat(fd, "..", O_CLOEXEC|O_NOFOLLOW|O_PATH);
|
||||
if (fd_parent < 0)
|
||||
@ -724,9 +722,7 @@ int chase_symlinks(const char *path, const char *_root, char **ret) {
|
||||
if (fd < 0)
|
||||
return -errno;
|
||||
|
||||
free(buffer);
|
||||
buffer = destination;
|
||||
destination = NULL;
|
||||
free_and_replace(buffer, destination);
|
||||
|
||||
todo = buffer;
|
||||
free(done);
|
||||
|
@ -288,9 +288,7 @@ char **path_strv_resolve(char **l, const char *prefix) {
|
||||
} else {
|
||||
/* canonicalized path goes outside of
|
||||
* prefix, keep the original path instead */
|
||||
free(u);
|
||||
u = orig;
|
||||
orig = NULL;
|
||||
free_and_replace(u, orig);
|
||||
}
|
||||
} else
|
||||
free(t);
|
||||
|
@ -62,9 +62,7 @@ Prioq* prioq_free(Prioq *q) {
|
||||
return NULL;
|
||||
|
||||
free(q->items);
|
||||
free(q);
|
||||
|
||||
return NULL;
|
||||
return mfree(q);
|
||||
}
|
||||
|
||||
int prioq_ensure_allocated(Prioq **q, compare_func_t compare_func) {
|
||||
|
@ -107,6 +107,5 @@ char *replace_var(const char *text, char *(*lookup)(const char *variable, void*u
|
||||
return r;
|
||||
|
||||
oom:
|
||||
free(r);
|
||||
return NULL;
|
||||
return mfree(r);
|
||||
}
|
||||
|
@ -62,8 +62,7 @@ struct strbuf *strbuf_new(void) {
|
||||
err:
|
||||
free(str->buf);
|
||||
free(str->root);
|
||||
free(str);
|
||||
return NULL;
|
||||
return mfree(str);
|
||||
}
|
||||
|
||||
static void strbuf_node_cleanup(struct strbuf_node *node) {
|
||||
|
@ -610,8 +610,7 @@ char *strreplace(const char *text, const char *old_string, const char *new_strin
|
||||
return r;
|
||||
|
||||
oom:
|
||||
free(r);
|
||||
return NULL;
|
||||
return mfree(r);
|
||||
}
|
||||
|
||||
char *strip_tab_ansi(char **ibuf, size_t *_isz) {
|
||||
@ -682,8 +681,7 @@ char *strip_tab_ansi(char **ibuf, size_t *_isz) {
|
||||
|
||||
if (ferror(f)) {
|
||||
fclose(f);
|
||||
free(obuf);
|
||||
return NULL;
|
||||
return mfree(obuf);
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
@ -87,8 +87,7 @@ void strv_clear(char **l) {
|
||||
|
||||
char **strv_free(char **l) {
|
||||
strv_clear(l);
|
||||
free(l);
|
||||
return NULL;
|
||||
return mfree(l);
|
||||
}
|
||||
|
||||
char **strv_free_erase(char **l) {
|
||||
@ -426,8 +425,7 @@ char *strv_join_quoted(char **l) {
|
||||
return buf;
|
||||
|
||||
oom:
|
||||
free(buf);
|
||||
return NULL;
|
||||
return mfree(buf);
|
||||
}
|
||||
|
||||
int strv_push(char ***l, char *value) {
|
||||
@ -869,8 +867,7 @@ char ***strv_free_free(char ***l) {
|
||||
for (i = l; *i; i++)
|
||||
strv_free(*i);
|
||||
|
||||
free(l);
|
||||
return NULL;
|
||||
return mfree(l);
|
||||
}
|
||||
|
||||
char **strv_skip(char **l, size_t n) {
|
||||
|
@ -42,9 +42,7 @@ static DynamicUser* dynamic_user_free(DynamicUser *d) {
|
||||
(void) hashmap_remove(d->manager->dynamic_users, d->name);
|
||||
|
||||
safe_close_pair(d->storage_socket);
|
||||
free(d);
|
||||
|
||||
return NULL;
|
||||
return mfree(d);
|
||||
}
|
||||
|
||||
static int dynamic_user_add(Manager *m, const char *name, int storage_socket[2], DynamicUser **ret) {
|
||||
|
@ -3740,9 +3740,7 @@ ExecRuntime *exec_runtime_unref(ExecRuntime *r) {
|
||||
free(r->tmp_dir);
|
||||
free(r->var_tmp_dir);
|
||||
safe_close_pair(r->netns_storage_socket);
|
||||
free(r);
|
||||
|
||||
return NULL;
|
||||
return mfree(r);
|
||||
}
|
||||
|
||||
int exec_runtime_serialize(Unit *u, ExecRuntime *rt, FILE *f, FDSet *fds) {
|
||||
|
@ -1591,11 +1591,7 @@ int config_parse_fdname(
|
||||
return 0;
|
||||
}
|
||||
|
||||
free(s->fdname);
|
||||
s->fdname = p;
|
||||
p = NULL;
|
||||
|
||||
return 0;
|
||||
return free_and_replace(s->fdname, p);
|
||||
}
|
||||
|
||||
int config_parse_service_sockets(
|
||||
@ -2052,9 +2048,7 @@ int config_parse_working_directory(
|
||||
return 0;
|
||||
}
|
||||
|
||||
free(c->working_directory);
|
||||
c->working_directory = k;
|
||||
k = NULL;
|
||||
free_and_replace(c->working_directory, k);
|
||||
|
||||
c->working_directory_home = false;
|
||||
}
|
||||
|
@ -1119,8 +1119,7 @@ Manager* manager_free(Manager *m) {
|
||||
hashmap_free(m->uid_refs);
|
||||
hashmap_free(m->gid_refs);
|
||||
|
||||
free(m);
|
||||
return NULL;
|
||||
return mfree(m);
|
||||
}
|
||||
|
||||
void manager_enumerate(Manager *m) {
|
||||
|
@ -1484,17 +1484,9 @@ static int mount_setup_unit(
|
||||
|
||||
MOUNT(u)->from_proc_self_mountinfo = true;
|
||||
|
||||
free(p->what);
|
||||
p->what = w;
|
||||
w = NULL;
|
||||
|
||||
free(p->options);
|
||||
p->options = o;
|
||||
o = NULL;
|
||||
|
||||
free(p->fstype);
|
||||
p->fstype = f;
|
||||
f = NULL;
|
||||
free_and_replace(p->what, w);
|
||||
free_and_replace(p->options, o);
|
||||
free_and_replace(p->fstype, f);
|
||||
|
||||
if (load_extras) {
|
||||
r = mount_add_extras(MOUNT(u));
|
||||
|
@ -3088,9 +3088,7 @@ static void service_notify_message(Unit *u, pid_t pid, char **tags, FDSet *fds)
|
||||
|
||||
if (!streq_ptr(s->status_text, t)) {
|
||||
|
||||
free(s->status_text);
|
||||
s->status_text = t;
|
||||
t = NULL;
|
||||
free_and_replace(s->status_text, t);
|
||||
|
||||
notify_dbus = true;
|
||||
}
|
||||
|
@ -1085,10 +1085,8 @@ Transaction *transaction_new(bool irreversible) {
|
||||
return NULL;
|
||||
|
||||
tr->jobs = hashmap_new(NULL);
|
||||
if (!tr->jobs) {
|
||||
free(tr);
|
||||
return NULL;
|
||||
}
|
||||
if (!tr->jobs)
|
||||
return mfree(tr);
|
||||
|
||||
tr->irreversible = irreversible;
|
||||
|
||||
|
@ -88,10 +88,8 @@ Unit *unit_new(Manager *m, size_t size) {
|
||||
return NULL;
|
||||
|
||||
u->names = set_new(&string_hash_ops);
|
||||
if (!u->names) {
|
||||
free(u);
|
||||
return NULL;
|
||||
}
|
||||
if (!u->names)
|
||||
return mfree(u);
|
||||
|
||||
u->manager = m;
|
||||
u->type = _UNIT_TYPE_INVALID;
|
||||
|
@ -264,16 +264,13 @@ static crypto_device *get_crypto_device(const char *uuid) {
|
||||
d->keyfile = d->options = d->name = NULL;
|
||||
|
||||
d->uuid = strdup(uuid);
|
||||
if (!d->uuid) {
|
||||
free(d);
|
||||
return NULL;
|
||||
}
|
||||
if (!d->uuid)
|
||||
return mfree(d);
|
||||
|
||||
r = hashmap_put(arg_disks, d->uuid, d);
|
||||
if (r < 0) {
|
||||
free(d->uuid);
|
||||
free(d);
|
||||
return NULL;
|
||||
return mfree(d);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -235,9 +235,7 @@ CurlGlue *curl_glue_unref(CurlGlue *g) {
|
||||
|
||||
sd_event_source_unref(g->timer);
|
||||
sd_event_unref(g->event);
|
||||
free(g);
|
||||
|
||||
return NULL;
|
||||
return mfree(g);
|
||||
}
|
||||
|
||||
int curl_glue_new(CurlGlue **glue, sd_event *event) {
|
||||
|
@ -87,9 +87,7 @@ RawExport *raw_export_unref(RawExport *e) {
|
||||
|
||||
free(e->buffer);
|
||||
free(e->path);
|
||||
free(e);
|
||||
|
||||
return NULL;
|
||||
return mfree(e);
|
||||
}
|
||||
|
||||
int raw_export_new(
|
||||
|
@ -91,9 +91,7 @@ TarExport *tar_export_unref(TarExport *e) {
|
||||
|
||||
free(e->buffer);
|
||||
free(e->path);
|
||||
free(e);
|
||||
|
||||
return NULL;
|
||||
return mfree(e);
|
||||
}
|
||||
|
||||
int tar_export_new(
|
||||
|
@ -100,9 +100,7 @@ RawImport* raw_import_unref(RawImport *i) {
|
||||
free(i->final_path);
|
||||
free(i->image_root);
|
||||
free(i->local);
|
||||
free(i);
|
||||
|
||||
return NULL;
|
||||
return mfree(i);
|
||||
}
|
||||
|
||||
int raw_import_new(
|
||||
|
@ -107,9 +107,7 @@ TarImport* tar_import_unref(TarImport *i) {
|
||||
free(i->final_path);
|
||||
free(i->image_root);
|
||||
free(i->local);
|
||||
free(i);
|
||||
|
||||
return NULL;
|
||||
return mfree(i);
|
||||
}
|
||||
|
||||
int tar_import_new(
|
||||
|
@ -141,8 +141,7 @@ static Transfer *transfer_unref(Transfer *t) {
|
||||
safe_close(t->stdin_fd);
|
||||
safe_close(t->stdout_fd);
|
||||
|
||||
free(t);
|
||||
return NULL;
|
||||
return mfree(t);
|
||||
}
|
||||
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(Transfer*, transfer_unref);
|
||||
@ -548,8 +547,7 @@ static Manager *manager_unref(Manager *m) {
|
||||
m->bus = sd_bus_flush_close_unref(m->bus);
|
||||
sd_event_unref(m->event);
|
||||
|
||||
free(m);
|
||||
return NULL;
|
||||
return mfree(m);
|
||||
}
|
||||
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_unref);
|
||||
|
@ -50,9 +50,7 @@ PullJob* pull_job_unref(PullJob *j) {
|
||||
free(j->payload);
|
||||
free(j->checksum);
|
||||
|
||||
free(j);
|
||||
|
||||
return NULL;
|
||||
return mfree(j);
|
||||
}
|
||||
|
||||
static void pull_job_finish(PullJob *j, int ret) {
|
||||
|
@ -110,9 +110,7 @@ RawPull* raw_pull_unref(RawPull *i) {
|
||||
free(i->settings_path);
|
||||
free(i->image_root);
|
||||
free(i->local);
|
||||
free(i);
|
||||
|
||||
return NULL;
|
||||
return mfree(i);
|
||||
}
|
||||
|
||||
int raw_pull_new(
|
||||
|
@ -114,9 +114,7 @@ TarPull* tar_pull_unref(TarPull *i) {
|
||||
free(i->settings_path);
|
||||
free(i->image_root);
|
||||
free(i->local);
|
||||
free(i);
|
||||
|
||||
return NULL;
|
||||
return mfree(i);
|
||||
}
|
||||
|
||||
int tar_pull_new(
|
||||
|
@ -75,10 +75,8 @@ Writer* writer_new(RemoteServer *server) {
|
||||
memset(&w->metrics, 0xFF, sizeof(w->metrics));
|
||||
|
||||
w->mmap = mmap_cache_new();
|
||||
if (!w->mmap) {
|
||||
free(w);
|
||||
return NULL;
|
||||
}
|
||||
if (!w->mmap)
|
||||
return mfree(w);
|
||||
|
||||
w->n_ref = 1;
|
||||
w->server = server;
|
||||
@ -103,9 +101,7 @@ Writer* writer_free(Writer *w) {
|
||||
if (w->mmap)
|
||||
mmap_cache_unref(w->mmap);
|
||||
|
||||
free(w);
|
||||
|
||||
return NULL;
|
||||
return mfree(w);
|
||||
}
|
||||
|
||||
Writer* writer_unref(Writer *w) {
|
||||
|
@ -527,9 +527,7 @@ static int perform_upload(Uploader *u) {
|
||||
log_debug("Upload finished successfully with code %ld: %s",
|
||||
status, strna(u->answer));
|
||||
|
||||
free(u->last_cursor);
|
||||
u->last_cursor = u->current_cursor;
|
||||
u->current_cursor = NULL;
|
||||
free_and_replace(u->last_cursor, u->current_cursor);
|
||||
|
||||
return update_cursor_state(u);
|
||||
}
|
||||
|
@ -394,8 +394,7 @@ JournalFile* journal_file_close(JournalFile *f) {
|
||||
gcry_md_close(f->hmac);
|
||||
#endif
|
||||
|
||||
free(f);
|
||||
return NULL;
|
||||
return mfree(f);
|
||||
}
|
||||
|
||||
void journal_file_close_set(Set *s) {
|
||||
|
@ -325,10 +325,8 @@ static FileDescriptor* fd_add(MMapCache *m, int fd) {
|
||||
f->fd = fd;
|
||||
|
||||
r = hashmap_put(m->fds, FD_TO_PTR(fd), f);
|
||||
if (r < 0) {
|
||||
free(f);
|
||||
return NULL;
|
||||
}
|
||||
if (r < 0)
|
||||
return mfree(f);
|
||||
|
||||
return f;
|
||||
}
|
||||
|
@ -387,7 +387,7 @@ _public_ int sd_journal_add_disjunction(sd_journal *j) {
|
||||
}
|
||||
|
||||
static char *match_make_string(Match *m) {
|
||||
char *p, *r;
|
||||
char *p = NULL, *r;
|
||||
Match *i;
|
||||
bool enclose = false;
|
||||
|
||||
@ -397,15 +397,12 @@ static char *match_make_string(Match *m) {
|
||||
if (m->type == MATCH_DISCRETE)
|
||||
return strndup(m->data, m->size);
|
||||
|
||||
p = NULL;
|
||||
LIST_FOREACH(matches, i, m->matches) {
|
||||
char *t, *k;
|
||||
|
||||
t = match_make_string(i);
|
||||
if (!t) {
|
||||
free(p);
|
||||
return NULL;
|
||||
}
|
||||
if (!t)
|
||||
return mfree(p);
|
||||
|
||||
if (p) {
|
||||
k = strjoin(p, m->type == MATCH_OR_TERM ? " OR " : " AND ", t, NULL);
|
||||
|
@ -49,8 +49,7 @@ _public_ sd_ndisc_router* sd_ndisc_router_unref(sd_ndisc_router *rt) {
|
||||
if (rt->n_ref > 0)
|
||||
return NULL;
|
||||
|
||||
free(rt);
|
||||
return NULL;
|
||||
return mfree(rt);
|
||||
}
|
||||
|
||||
sd_ndisc_router *ndisc_router_new(size_t raw_size) {
|
||||
|
@ -1873,9 +1873,7 @@ sd_dhcp_client *sd_dhcp_client_unref(sd_dhcp_client *client) {
|
||||
free(client->req_opts);
|
||||
free(client->hostname);
|
||||
free(client->vendor_class_identifier);
|
||||
free(client);
|
||||
|
||||
return NULL;
|
||||
return mfree(client);
|
||||
}
|
||||
|
||||
int sd_dhcp_client_new(sd_dhcp_client **ret) {
|
||||
|
@ -282,9 +282,7 @@ sd_dhcp_lease *sd_dhcp_lease_unref(sd_dhcp_lease *lease) {
|
||||
free(lease->static_route);
|
||||
free(lease->client_id);
|
||||
free(lease->vendor_specific);
|
||||
free(lease);
|
||||
|
||||
return NULL;
|
||||
return mfree(lease);
|
||||
}
|
||||
|
||||
static int lease_parse_u32(const uint8_t *option, size_t len, uint32_t *ret, uint32_t min) {
|
||||
|
@ -178,9 +178,7 @@ sd_dhcp_server *sd_dhcp_server_unref(sd_dhcp_server *server) {
|
||||
hashmap_free(server->leases_by_client_id);
|
||||
|
||||
free(server->bound_leases);
|
||||
free(server);
|
||||
|
||||
return NULL;
|
||||
return mfree(server);
|
||||
}
|
||||
|
||||
int sd_dhcp_server_new(sd_dhcp_server **ret, int ifindex) {
|
||||
|
@ -1300,9 +1300,7 @@ sd_dhcp6_client *sd_dhcp6_client_unref(sd_dhcp6_client *client) {
|
||||
sd_dhcp6_client_detach_event(client);
|
||||
|
||||
free(client->req_opts);
|
||||
free(client);
|
||||
|
||||
return NULL;
|
||||
return mfree(client);
|
||||
}
|
||||
|
||||
int sd_dhcp6_client_new(sd_dhcp6_client **ret) {
|
||||
|
@ -389,9 +389,7 @@ sd_dhcp6_lease *sd_dhcp6_lease_unref(sd_dhcp6_lease *lease) {
|
||||
free(lease->ntp);
|
||||
|
||||
lease->ntp_fqdn = strv_free(lease->ntp_fqdn);
|
||||
free(lease);
|
||||
|
||||
return NULL;
|
||||
return mfree(lease);
|
||||
}
|
||||
|
||||
int dhcp6_lease_new(sd_dhcp6_lease **ret) {
|
||||
|
@ -135,9 +135,7 @@ sd_ipv4acd *sd_ipv4acd_unref(sd_ipv4acd *acd) {
|
||||
ipv4acd_reset(acd);
|
||||
sd_ipv4acd_detach_event(acd);
|
||||
|
||||
free(acd);
|
||||
|
||||
return NULL;
|
||||
return mfree(acd);
|
||||
}
|
||||
|
||||
int sd_ipv4acd_new(sd_ipv4acd **ret) {
|
||||
|
@ -90,9 +90,7 @@ sd_ipv4ll *sd_ipv4ll_unref(sd_ipv4ll *ll) {
|
||||
return NULL;
|
||||
|
||||
sd_ipv4acd_unref(ll->acd);
|
||||
free(ll);
|
||||
|
||||
return NULL;
|
||||
return mfree(ll);
|
||||
}
|
||||
|
||||
int sd_ipv4ll_new(sd_ipv4ll **ret) {
|
||||
|
@ -374,9 +374,7 @@ _public_ sd_lldp* sd_lldp_unref(sd_lldp *lldp) {
|
||||
|
||||
hashmap_free(lldp->neighbor_by_id);
|
||||
prioq_free(lldp->neighbor_by_expiry);
|
||||
free(lldp);
|
||||
|
||||
return NULL;
|
||||
return mfree(lldp);
|
||||
}
|
||||
|
||||
_public_ int sd_lldp_new(sd_lldp **ret) {
|
||||
|
@ -148,9 +148,7 @@ _public_ sd_ndisc *sd_ndisc_unref(sd_ndisc *nd) {
|
||||
|
||||
ndisc_reset(nd);
|
||||
sd_ndisc_detach_event(nd);
|
||||
free(nd);
|
||||
|
||||
return NULL;
|
||||
return mfree(nd);
|
||||
}
|
||||
|
||||
_public_ int sd_ndisc_new(sd_ndisc **ret) {
|
||||
|
@ -212,9 +212,7 @@ _public_ sd_bus_slot* sd_bus_slot_unref(sd_bus_slot *slot) {
|
||||
|
||||
bus_slot_disconnect(slot);
|
||||
free(slot->description);
|
||||
free(slot);
|
||||
|
||||
return NULL;
|
||||
return mfree(slot);
|
||||
}
|
||||
|
||||
_public_ sd_bus* sd_bus_slot_get_bus(sd_bus_slot *slot) {
|
||||
|
@ -74,9 +74,7 @@ static struct track_item* track_item_free(struct track_item *i) {
|
||||
|
||||
sd_bus_slot_unref(i->slot);
|
||||
free(i->name);
|
||||
free(i);
|
||||
|
||||
return NULL;
|
||||
return mfree(i);
|
||||
}
|
||||
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(struct track_item*, track_item_free);
|
||||
@ -206,9 +204,7 @@ _public_ sd_bus_track* sd_bus_track_unref(sd_bus_track *track) {
|
||||
bus_track_remove_from_queue(track);
|
||||
hashmap_free(track->names);
|
||||
sd_bus_unref(track->bus);
|
||||
free(track);
|
||||
|
||||
return NULL;
|
||||
return mfree(track);
|
||||
}
|
||||
|
||||
static int on_name_owner_changed(sd_bus_message *message, void *userdata, sd_bus_error *error) {
|
||||
|
@ -166,17 +166,16 @@ struct udev_list_entry *udev_list_entry_add(struct udev_list *list, const char *
|
||||
entry = new0(struct udev_list_entry, 1);
|
||||
if (entry == NULL)
|
||||
return NULL;
|
||||
|
||||
entry->name = strdup(name);
|
||||
if (entry->name == NULL) {
|
||||
free(entry);
|
||||
return NULL;
|
||||
}
|
||||
if (entry->name == NULL)
|
||||
return mfree(entry);
|
||||
|
||||
if (value != NULL) {
|
||||
entry->value = strdup(value);
|
||||
if (entry->value == NULL) {
|
||||
free(entry->name);
|
||||
free(entry);
|
||||
return NULL;
|
||||
return mfree(entry);
|
||||
}
|
||||
}
|
||||
|
||||
@ -193,8 +192,7 @@ struct udev_list_entry *udev_list_entry_add(struct udev_list *list, const char *
|
||||
if (entries == NULL) {
|
||||
free(entry->name);
|
||||
free(entry->value);
|
||||
free(entry);
|
||||
return NULL;
|
||||
return mfree(entry);
|
||||
}
|
||||
list->entries = entries;
|
||||
list->entries_max += add;
|
||||
|
@ -207,8 +207,7 @@ struct udev_monitor *udev_monitor_new_from_netlink_fd(struct udev *udev, const c
|
||||
udev_monitor->sock = socket(PF_NETLINK, SOCK_RAW|SOCK_CLOEXEC|SOCK_NONBLOCK, NETLINK_KOBJECT_UEVENT);
|
||||
if (udev_monitor->sock < 0) {
|
||||
log_debug_errno(errno, "error getting socket: %m");
|
||||
free(udev_monitor);
|
||||
return NULL;
|
||||
return mfree(udev_monitor);
|
||||
}
|
||||
} else {
|
||||
udev_monitor->bound = true;
|
||||
|
@ -43,15 +43,12 @@ Button* button_new(Manager *m, const char *name) {
|
||||
return NULL;
|
||||
|
||||
b->name = strdup(name);
|
||||
if (!b->name) {
|
||||
free(b);
|
||||
return NULL;
|
||||
}
|
||||
if (!b->name)
|
||||
return mfree(b);
|
||||
|
||||
if (hashmap_put(m->buttons, b->name, b) < 0) {
|
||||
free(b->name);
|
||||
free(b);
|
||||
return NULL;
|
||||
return mfree(b);
|
||||
}
|
||||
|
||||
b->manager = m;
|
||||
|
@ -34,15 +34,12 @@ Device* device_new(Manager *m, const char *sysfs, bool master) {
|
||||
return NULL;
|
||||
|
||||
d->sysfs = strdup(sysfs);
|
||||
if (!d->sysfs) {
|
||||
free(d);
|
||||
return NULL;
|
||||
}
|
||||
if (!d->sysfs)
|
||||
return mfree(d);
|
||||
|
||||
if (hashmap_put(m->devices, d->sysfs, d) < 0) {
|
||||
free(d->sysfs);
|
||||
free(d);
|
||||
return NULL;
|
||||
return mfree(d);
|
||||
}
|
||||
|
||||
d->manager = m;
|
||||
|
@ -45,17 +45,14 @@ Inhibitor* inhibitor_new(Manager *m, const char* id) {
|
||||
return NULL;
|
||||
|
||||
i->state_file = strappend("/run/systemd/inhibit/", id);
|
||||
if (!i->state_file) {
|
||||
free(i);
|
||||
return NULL;
|
||||
}
|
||||
if (!i->state_file)
|
||||
return mfree(i);
|
||||
|
||||
i->id = basename(i->state_file);
|
||||
|
||||
if (hashmap_put(m->inhibitors, i->id, i) < 0) {
|
||||
free(i->state_file);
|
||||
free(i);
|
||||
return NULL;
|
||||
return mfree(i);
|
||||
}
|
||||
|
||||
i->manager = m;
|
||||
|
@ -48,18 +48,15 @@ Seat *seat_new(Manager *m, const char *id) {
|
||||
return NULL;
|
||||
|
||||
s->state_file = strappend("/run/systemd/seats/", id);
|
||||
if (!s->state_file) {
|
||||
free(s);
|
||||
return NULL;
|
||||
}
|
||||
if (!s->state_file)
|
||||
return mfree(s);
|
||||
|
||||
s->id = basename(s->state_file);
|
||||
s->manager = m;
|
||||
|
||||
if (hashmap_put(m->seats, s->id, s) < 0) {
|
||||
free(s->state_file);
|
||||
free(s);
|
||||
return NULL;
|
||||
return mfree(s);
|
||||
}
|
||||
|
||||
return s;
|
||||
|
@ -62,16 +62,13 @@ Session* session_new(Manager *m, const char *id) {
|
||||
return NULL;
|
||||
|
||||
s->state_file = strappend("/run/systemd/sessions/", id);
|
||||
if (!s->state_file) {
|
||||
free(s);
|
||||
return NULL;
|
||||
}
|
||||
if (!s->state_file)
|
||||
return mfree(s);
|
||||
|
||||
s->devices = hashmap_new(&devt_hash_ops);
|
||||
if (!s->devices) {
|
||||
free(s->state_file);
|
||||
free(s);
|
||||
return NULL;
|
||||
return mfree(s);
|
||||
}
|
||||
|
||||
s->id = basename(s->state_file);
|
||||
@ -79,8 +76,7 @@ Session* session_new(Manager *m, const char *id) {
|
||||
if (hashmap_put(m->sessions, s->id, s) < 0) {
|
||||
hashmap_free(s->devices);
|
||||
free(s->state_file);
|
||||
free(s);
|
||||
return NULL;
|
||||
return mfree(s);
|
||||
}
|
||||
|
||||
s->manager = m;
|
||||
|
@ -80,9 +80,7 @@ Machine* machine_new(Manager *manager, MachineClass class, const char *name) {
|
||||
fail:
|
||||
free(m->state_file);
|
||||
free(m->name);
|
||||
free(m);
|
||||
|
||||
return NULL;
|
||||
return mfree(m);
|
||||
}
|
||||
|
||||
void machine_free(Machine *m) {
|
||||
|
@ -147,6 +147,5 @@ Operation *operation_free(Operation *o) {
|
||||
if (o->machine)
|
||||
LIST_REMOVE(operations_by_machine, o->machine->operations, o);
|
||||
|
||||
free(o);
|
||||
return NULL;
|
||||
return mfree(o);
|
||||
}
|
||||
|
@ -77,8 +77,7 @@ Link *link_free(Link *l) {
|
||||
}
|
||||
|
||||
free(l->ifname);
|
||||
free(l);
|
||||
return NULL;
|
||||
return mfree(l);
|
||||
}
|
||||
|
||||
int link_update_rtnl(Link *l, sd_netlink_message *m) {
|
||||
|
@ -101,9 +101,7 @@ Settings* settings_free(Settings *s) {
|
||||
expose_port_free_all(s->expose_ports);
|
||||
|
||||
custom_mount_free_all(s->custom_mounts, s->n_custom_mounts);
|
||||
free(s);
|
||||
|
||||
return NULL;
|
||||
return mfree(s);
|
||||
}
|
||||
|
||||
bool settings_private_network(Settings *s) {
|
||||
|
@ -83,9 +83,7 @@ DnsQueryCandidate* dns_query_candidate_free(DnsQueryCandidate *c) {
|
||||
if (c->scope)
|
||||
LIST_REMOVE(candidates_by_scope, c->scope->query_candidates, c);
|
||||
|
||||
free(c);
|
||||
|
||||
return NULL;
|
||||
return mfree(c);
|
||||
}
|
||||
|
||||
static int dns_query_candidate_next_search_domain(DnsQueryCandidate *c) {
|
||||
@ -421,9 +419,7 @@ DnsQuery *dns_query_free(DnsQuery *q) {
|
||||
q->manager->n_dns_queries--;
|
||||
}
|
||||
|
||||
free(q);
|
||||
|
||||
return NULL;
|
||||
return mfree(q);
|
||||
}
|
||||
|
||||
int dns_query_new(
|
||||
|
@ -73,10 +73,8 @@ DnsResourceKey* dns_resource_key_new_redirect(const DnsResourceKey *key, const D
|
||||
return dns_resource_key_ref((DnsResourceKey*) key);
|
||||
|
||||
k = dns_resource_key_new_consume(key->class, key->type, destination);
|
||||
if (!k) {
|
||||
free(destination);
|
||||
return NULL;
|
||||
}
|
||||
if (!k)
|
||||
return mfree(destination);
|
||||
|
||||
return k;
|
||||
}
|
||||
@ -513,9 +511,7 @@ DnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr) {
|
||||
}
|
||||
|
||||
free(rr->to_string);
|
||||
free(rr);
|
||||
|
||||
return NULL;
|
||||
return mfree(rr);
|
||||
}
|
||||
|
||||
int dns_resource_record_new_reverse(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *hostname) {
|
||||
|
@ -128,9 +128,7 @@ DnsScope* dns_scope_free(DnsScope *s) {
|
||||
dns_zone_flush(&s->zone);
|
||||
|
||||
LIST_REMOVE(scopes, s->manager->dns_scopes, s);
|
||||
free(s);
|
||||
|
||||
return NULL;
|
||||
return mfree(s);
|
||||
}
|
||||
|
||||
DnsServer *dns_scope_get_dns_server(DnsScope *s) {
|
||||
|
@ -104,9 +104,7 @@ DnsSearchDomain* dns_search_domain_unref(DnsSearchDomain *d) {
|
||||
return NULL;
|
||||
|
||||
free(d->name);
|
||||
free(d);
|
||||
|
||||
return NULL;
|
||||
return mfree(d);
|
||||
}
|
||||
|
||||
void dns_search_domain_unlink(DnsSearchDomain *d) {
|
||||
|
@ -139,8 +139,7 @@ DnsServer* dns_server_unref(DnsServer *s) {
|
||||
return NULL;
|
||||
|
||||
free(s->server_string);
|
||||
free(s);
|
||||
return NULL;
|
||||
return mfree(s);
|
||||
}
|
||||
|
||||
void dns_server_unlink(DnsServer *s) {
|
||||
|
@ -343,9 +343,7 @@ DnsStream *dns_stream_unref(DnsStream *s) {
|
||||
dns_packet_unref(s->write_packet);
|
||||
dns_packet_unref(s->read_packet);
|
||||
|
||||
free(s);
|
||||
|
||||
return NULL;
|
||||
return mfree(s);
|
||||
}
|
||||
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(DnsStream*, dns_stream_unref);
|
||||
|
@ -134,8 +134,7 @@ DnsTransaction* dns_transaction_free(DnsTransaction *t) {
|
||||
dns_answer_unref(t->validated_keys);
|
||||
dns_resource_key_unref(t->key);
|
||||
|
||||
free(t);
|
||||
return NULL;
|
||||
return mfree(t);
|
||||
}
|
||||
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(DnsTransaction*, dns_transaction_free);
|
||||
|
@ -101,8 +101,7 @@ Link *link_free(Link *l) {
|
||||
|
||||
free(l->state_file);
|
||||
|
||||
free(l);
|
||||
return NULL;
|
||||
return mfree(l);
|
||||
}
|
||||
|
||||
void link_allocate_scopes(Link *l) {
|
||||
@ -698,8 +697,7 @@ LinkAddress *link_address_free(LinkAddress *a) {
|
||||
dns_resource_record_unref(a->llmnr_address_rr);
|
||||
dns_resource_record_unref(a->llmnr_ptr_rr);
|
||||
|
||||
free(a);
|
||||
return NULL;
|
||||
return mfree(a);
|
||||
}
|
||||
|
||||
void link_address_add_rrs(LinkAddress *a, bool force_remove) {
|
||||
|
@ -630,9 +630,7 @@ Manager *manager_free(Manager *m) {
|
||||
dns_trust_anchor_flush(&m->trust_anchor);
|
||||
manager_etc_hosts_flush(m);
|
||||
|
||||
free(m);
|
||||
|
||||
return NULL;
|
||||
return mfree(m);
|
||||
}
|
||||
|
||||
int manager_recv(Manager *m, int fd, DnsProtocol protocol, DnsPacket **ret) {
|
||||
|
@ -214,8 +214,8 @@ static int path_is_config(const LookupPaths *p, const char *path) {
|
||||
assert(p);
|
||||
assert(path);
|
||||
|
||||
/* Note that we do *not* have generic checks for /etc or /run in place, since with them we couldn't discern
|
||||
* configuration from transient or generated units */
|
||||
/* Note that we do *not* have generic checks for /etc or /run in place, since with
|
||||
* them we couldn't discern configuration from transient or generated units */
|
||||
|
||||
parent = dirname_malloc(path);
|
||||
if (!parent)
|
||||
@ -232,8 +232,8 @@ static int path_is_runtime(const LookupPaths *p, const char *path) {
|
||||
assert(p);
|
||||
assert(path);
|
||||
|
||||
/* Everything in /run is considered runtime. On top of that we also add explicit checks for the various runtime
|
||||
* directories, as safety net. */
|
||||
/* Everything in /run is considered runtime. On top of that we also add
|
||||
* explicit checks for the various runtime directories, as safety net. */
|
||||
|
||||
rpath = skip_root(p, path);
|
||||
if (rpath && path_startswith(rpath, "/run"))
|
||||
@ -1084,7 +1084,7 @@ static int config_parse_default_instance(
|
||||
|
||||
UnitFileInstallInfo *i = data;
|
||||
const char *name;
|
||||
char *printed;
|
||||
_cleanup_free_ char *printed = NULL;
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
@ -1104,15 +1104,10 @@ static int config_parse_default_instance(
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (!unit_instance_is_valid(printed)) {
|
||||
free(printed);
|
||||
if (!unit_instance_is_valid(printed))
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
free(i->default_instance);
|
||||
i->default_instance = printed;
|
||||
|
||||
return 0;
|
||||
return free_and_replace(i->default_instance, printed);
|
||||
}
|
||||
|
||||
static int unit_file_load(
|
||||
@ -1358,9 +1353,7 @@ static int install_info_follow(
|
||||
if (!streq(basename(i->symlink_target), i->name))
|
||||
return -EXDEV;
|
||||
|
||||
free(i->path);
|
||||
i->path = i->symlink_target;
|
||||
i->symlink_target = NULL;
|
||||
free_and_replace(i->path, i->symlink_target);
|
||||
i->type = _UNIT_FILE_TYPE_INVALID;
|
||||
|
||||
return unit_file_load_or_readlink(c, i, i->path, root_dir, flags);
|
||||
|
@ -62,8 +62,7 @@ Image *image_unref(Image *i) {
|
||||
|
||||
free(i->name);
|
||||
free(i->path);
|
||||
free(i);
|
||||
return NULL;
|
||||
return mfree(i);
|
||||
}
|
||||
|
||||
static char **image_settings_path(Image *image) {
|
||||
|
@ -463,8 +463,7 @@ int pty_forward_new(
|
||||
|
||||
PTYForward *pty_forward_free(PTYForward *f) {
|
||||
pty_forward_disconnect(f);
|
||||
free(f);
|
||||
return NULL;
|
||||
return mfree(f);
|
||||
}
|
||||
|
||||
int pty_forward_get_last_char(PTYForward *f, char *ch) {
|
||||
|
@ -61,8 +61,7 @@ ServerAddress* server_address_free(ServerAddress *a) {
|
||||
manager_set_server_address(a->name->manager, NULL);
|
||||
}
|
||||
|
||||
free(a);
|
||||
return NULL;
|
||||
return mfree(a);
|
||||
}
|
||||
|
||||
int server_name_new(
|
||||
@ -137,9 +136,7 @@ ServerName *server_name_free(ServerName *n) {
|
||||
log_debug("Removed server %s.", n->string);
|
||||
|
||||
free(n->string);
|
||||
free(n);
|
||||
|
||||
return NULL;
|
||||
return mfree(n);
|
||||
}
|
||||
|
||||
void server_name_flush_addresses(ServerName *n) {
|
||||
|
@ -211,8 +211,7 @@ struct udev_ctrl_connection *udev_ctrl_get_connection(struct udev_ctrl *uctrl) {
|
||||
err:
|
||||
if (conn->sock >= 0)
|
||||
close(conn->sock);
|
||||
free(conn);
|
||||
return NULL;
|
||||
return mfree(conn);
|
||||
}
|
||||
|
||||
struct udev_ctrl_connection *udev_ctrl_connection_ref(struct udev_ctrl_connection *conn) {
|
||||
|
@ -1583,8 +1583,7 @@ struct udev_rules *udev_rules_unref(struct udev_rules *rules) {
|
||||
strbuf_cleanup(rules->strbuf);
|
||||
free(rules->uids);
|
||||
free(rules->gids);
|
||||
free(rules);
|
||||
return NULL;
|
||||
return mfree(rules);
|
||||
}
|
||||
|
||||
bool udev_rules_check_timestamp(struct udev_rules *rules) {
|
||||
|
Loading…
Reference in New Issue
Block a user