summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/basic/alloc-util.h8
-rw-r--r--src/basic/bitmap.c6
-rw-r--r--src/basic/env-util.c3
-rw-r--r--src/basic/fs-util.c8
-rw-r--r--src/basic/path-util.c4
-rw-r--r--src/basic/prioq.c4
-rw-r--r--src/basic/replace-var.c3
-rw-r--r--src/basic/strbuf.c3
-rw-r--r--src/basic/string-util.c6
-rw-r--r--src/basic/strv.c9
-rw-r--r--src/core/dynamic-user.c4
-rw-r--r--src/core/execute.c4
-rw-r--r--src/core/load-fragment.c10
-rw-r--r--src/core/manager.c3
-rw-r--r--src/core/mount.c14
-rw-r--r--src/core/service.c4
-rw-r--r--src/core/transaction.c6
-rw-r--r--src/core/unit.c26
-rw-r--r--src/cryptsetup/cryptsetup-generator.c9
-rw-r--r--src/import/curl-util.c4
-rw-r--r--src/import/export-raw.c4
-rw-r--r--src/import/export-tar.c4
-rw-r--r--src/import/import-raw.c4
-rw-r--r--src/import/import-tar.c4
-rw-r--r--src/import/importd.c6
-rw-r--r--src/import/pull-job.c4
-rw-r--r--src/import/pull-raw.c4
-rw-r--r--src/import/pull-tar.c4
-rw-r--r--src/journal-remote/journal-remote-write.c10
-rw-r--r--src/journal-remote/journal-upload.c4
-rw-r--r--src/journal/journal-file.c3
-rw-r--r--src/journal/mmap-cache.c6
-rw-r--r--src/journal/sd-journal.c9
-rw-r--r--src/libsystemd-network/ndisc-router.c3
-rw-r--r--src/libsystemd-network/sd-dhcp-client.c4
-rw-r--r--src/libsystemd-network/sd-dhcp-lease.c4
-rw-r--r--src/libsystemd-network/sd-dhcp-server.c4
-rw-r--r--src/libsystemd-network/sd-dhcp6-client.c4
-rw-r--r--src/libsystemd-network/sd-dhcp6-lease.c4
-rw-r--r--src/libsystemd-network/sd-ipv4acd.c4
-rw-r--r--src/libsystemd-network/sd-ipv4ll.c4
-rw-r--r--src/libsystemd-network/sd-lldp.c4
-rw-r--r--src/libsystemd-network/sd-ndisc.c4
-rw-r--r--src/libsystemd/sd-bus/bus-slot.c4
-rw-r--r--src/libsystemd/sd-bus/bus-track.c8
-rw-r--r--src/libudev/libudev-list.c14
-rw-r--r--src/libudev/libudev-monitor.c3
-rw-r--r--src/login/loginctl.c90
-rw-r--r--src/login/logind-button.c9
-rw-r--r--src/login/logind-device.c9
-rw-r--r--src/login/logind-inhibit.c9
-rw-r--r--src/login/logind-seat.c9
-rw-r--r--src/login/logind-session.c12
-rw-r--r--src/machine/machine.c4
-rw-r--r--src/machine/operation.c3
-rw-r--r--src/network/networkd-wait-online-link.c3
-rw-r--r--src/nspawn/nspawn-settings.c4
-rw-r--r--src/resolve/resolved-dns-query.c8
-rw-r--r--src/resolve/resolved-dns-rr.c10
-rw-r--r--src/resolve/resolved-dns-scope.c4
-rw-r--r--src/resolve/resolved-dns-search-domain.c4
-rw-r--r--src/resolve/resolved-dns-server.c3
-rw-r--r--src/resolve/resolved-dns-stream.c4
-rw-r--r--src/resolve/resolved-dns-transaction.c3
-rw-r--r--src/resolve/resolved-link.c6
-rw-r--r--src/resolve/resolved-manager.c4
-rw-r--r--src/shared/install.c23
-rw-r--r--src/shared/machine-image.c3
-rw-r--r--src/shared/ptyfwd.c3
-rw-r--r--src/timesync/timesyncd-server.c7
-rw-r--r--src/udev/udev-ctrl.c3
-rw-r--r--src/udev/udev-rules.c3
72 files changed, 204 insertions, 308 deletions
diff --git a/src/basic/alloc-util.h b/src/basic/alloc-util.h
index ceeee519b7..a44dd473c1 100644
--- a/src/basic/alloc-util.h
+++ b/src/basic/alloc-util.h
@@ -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) {
diff --git a/src/basic/bitmap.c b/src/basic/bitmap.c
index f4b12fc261..f6212e6151 100644
--- a/src/basic/bitmap.c
+++ b/src/basic/bitmap.c
@@ -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;
diff --git a/src/basic/env-util.c b/src/basic/env-util.c
index 7f5fddb700..b74290d6fd 100644
--- a/src/basic/env-util.c
+++ b/src/basic/env-util.c
@@ -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) {
diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c
index 86d9ad7e36..48952a1c26 100644
--- a/src/basic/fs-util.c
+++ b/src/basic/fs-util.c
@@ -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);
diff --git a/src/basic/path-util.c b/src/basic/path-util.c
index a76963aa9f..0f5b20cf05 100644
--- a/src/basic/path-util.c
+++ b/src/basic/path-util.c
@@ -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);
diff --git a/src/basic/prioq.c b/src/basic/prioq.c
index d2ec516d29..4570b8e4ba 100644
--- a/src/basic/prioq.c
+++ b/src/basic/prioq.c
@@ -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) {
diff --git a/src/basic/replace-var.c b/src/basic/replace-var.c
index 6a204b9ec3..0d21423a9c 100644
--- a/src/basic/replace-var.c
+++ b/src/basic/replace-var.c
@@ -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);
}
diff --git a/src/basic/strbuf.c b/src/basic/strbuf.c
index 4bef87d3c2..00aaf9e621 100644
--- a/src/basic/strbuf.c
+++ b/src/basic/strbuf.c
@@ -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) {
diff --git a/src/basic/string-util.c b/src/basic/string-util.c
index dc7de5dab8..6b06e643c9 100644
--- a/src/basic/string-util.c
+++ b/src/basic/string-util.c
@@ -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);
diff --git a/src/basic/strv.c b/src/basic/strv.c
index 34e464d253..0eec868eed 100644
--- a/src/basic/strv.c
+++ b/src/basic/strv.c
@@ -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) {
diff --git a/src/core/dynamic-user.c b/src/core/dynamic-user.c
index 1043da3eb7..e1846e1adb 100644
--- a/src/core/dynamic-user.c
+++ b/src/core/dynamic-user.c
@@ -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) {
diff --git a/src/core/execute.c b/src/core/execute.c
index 869522704a..59c2bd0dd2 100644
--- a/src/core/execute.c
+++ b/src/core/execute.c
@@ -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) {
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index 06c156a623..8cc7a8e765 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -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;
}
diff --git a/src/core/manager.c b/src/core/manager.c
index 3569249788..50aae0d1ba 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -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) {
diff --git a/src/core/mount.c b/src/core/mount.c
index 15619dffe3..da480001e1 100644
--- a/src/core/mount.c
+++ b/src/core/mount.c
@@ -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));
diff --git a/src/core/service.c b/src/core/service.c
index 63045ede55..c949de9cbe 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -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;
}
diff --git a/src/core/transaction.c b/src/core/transaction.c
index 8370b864fb..e22e3b30c2 100644
--- a/src/core/transaction.c
+++ b/src/core/transaction.c
@@ -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;
diff --git a/src/core/unit.c b/src/core/unit.c
index 67668bdc48..b24ca5aed8 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -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;
@@ -3055,7 +3053,7 @@ int unit_coldplug(Unit *u) {
return r;
}
-static bool fragment_mtime_newer(const char *path, usec_t mtime) {
+static bool fragment_mtime_newer(const char *path, usec_t mtime, bool path_masked) {
struct stat st;
if (!path)
@@ -3065,12 +3063,12 @@ static bool fragment_mtime_newer(const char *path, usec_t mtime) {
/* What, cannot access this anymore? */
return true;
- if (mtime > 0)
+ if (path_masked)
+ /* For masked files check if they are still so */
+ return !null_or_empty(&st);
+ else
/* For non-empty files check the mtime */
return timespec_load(&st.st_mtim) > mtime;
- else if (!null_or_empty(&st))
- /* For masked files check if they are still so */
- return true;
return false;
}
@@ -3081,18 +3079,22 @@ bool unit_need_daemon_reload(Unit *u) {
assert(u);
- if (fragment_mtime_newer(u->fragment_path, u->fragment_mtime))
+ /* For unit files, we allow masking… */
+ if (fragment_mtime_newer(u->fragment_path, u->fragment_mtime,
+ u->load_state == UNIT_MASKED))
return true;
- if (fragment_mtime_newer(u->source_path, u->source_mtime))
+ /* Source paths should not be masked… */
+ if (fragment_mtime_newer(u->source_path, u->source_mtime, false))
return true;
(void) unit_find_dropin_paths(u, &t);
if (!strv_equal(u->dropin_paths, t))
return true;
+ /* … any drop-ins that are masked are simply omitted from the list. */
STRV_FOREACH(path, u->dropin_paths)
- if (fragment_mtime_newer(*path, u->dropin_mtime))
+ if (fragment_mtime_newer(*path, u->dropin_mtime, false))
return true;
return false;
diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c
index 8ac5ab730a..de0a3b6f9c 100644
--- a/src/cryptsetup/cryptsetup-generator.c
+++ b/src/cryptsetup/cryptsetup-generator.c
@@ -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);
}
}
diff --git a/src/import/curl-util.c b/src/import/curl-util.c
index 6990c47f48..734e1560e6 100644
--- a/src/import/curl-util.c
+++ b/src/import/curl-util.c
@@ -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) {
diff --git a/src/import/export-raw.c b/src/import/export-raw.c
index 6136b677dd..a3dbce1954 100644
--- a/src/import/export-raw.c
+++ b/src/import/export-raw.c
@@ -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(
diff --git a/src/import/export-tar.c b/src/import/export-tar.c
index d79c27f2d0..3bb6027431 100644
--- a/src/import/export-tar.c
+++ b/src/import/export-tar.c
@@ -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(
diff --git a/src/import/import-raw.c b/src/import/import-raw.c
index fd6b9f7703..29f3f896e5 100644
--- a/src/import/import-raw.c
+++ b/src/import/import-raw.c
@@ -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(
diff --git a/src/import/import-tar.c b/src/import/import-tar.c
index 8b81324fde..22f9b8c5ea 100644
--- a/src/import/import-tar.c
+++ b/src/import/import-tar.c
@@ -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(
diff --git a/src/import/importd.c b/src/import/importd.c
index 28b4302cb3..9d31a956a5 100644
--- a/src/import/importd.c
+++ b/src/import/importd.c
@@ -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);
diff --git a/src/import/pull-job.c b/src/import/pull-job.c
index 6bcf35ef4e..e550df2c57 100644
--- a/src/import/pull-job.c
+++ b/src/import/pull-job.c
@@ -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) {
diff --git a/src/import/pull-raw.c b/src/import/pull-raw.c
index 8993402821..0cf410a5d9 100644
--- a/src/import/pull-raw.c
+++ b/src/import/pull-raw.c
@@ -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(
diff --git a/src/import/pull-tar.c b/src/import/pull-tar.c
index 8c61c46f73..68e2397b02 100644
--- a/src/import/pull-tar.c
+++ b/src/import/pull-tar.c
@@ -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(
diff --git a/src/journal-remote/journal-remote-write.c b/src/journal-remote/journal-remote-write.c
index 7bba52566e..8729372aa3 100644
--- a/src/journal-remote/journal-remote-write.c
+++ b/src/journal-remote/journal-remote-write.c
@@ -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) {
diff --git a/src/journal-remote/journal-upload.c b/src/journal-remote/journal-upload.c
index c0f967ab94..61190ff83c 100644
--- a/src/journal-remote/journal-upload.c
+++ b/src/journal-remote/journal-upload.c
@@ -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);
}
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index 49199b269f..d3e0214731 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -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) {
diff --git a/src/journal/mmap-cache.c b/src/journal/mmap-cache.c
index 293d27053a..d91247b524 100644
--- a/src/journal/mmap-cache.c
+++ b/src/journal/mmap-cache.c
@@ -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;
}
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index 98c8a47afe..f2f8546086 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -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);
diff --git a/src/libsystemd-network/ndisc-router.c b/src/libsystemd-network/ndisc-router.c
index d9950b638c..41ff2b353a 100644
--- a/src/libsystemd-network/ndisc-router.c
+++ b/src/libsystemd-network/ndisc-router.c
@@ -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) {
diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c
index 179e5950bd..5ccb23922c 100644
--- a/src/libsystemd-network/sd-dhcp-client.c
+++ b/src/libsystemd-network/sd-dhcp-client.c
@@ -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) {
diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c
index ef50ed17a1..8387b185c0 100644
--- a/src/libsystemd-network/sd-dhcp-lease.c
+++ b/src/libsystemd-network/sd-dhcp-lease.c
@@ -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) {
diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c
index 11ee2e252e..f16314a37f 100644
--- a/src/libsystemd-network/sd-dhcp-server.c
+++ b/src/libsystemd-network/sd-dhcp-server.c
@@ -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) {
diff --git a/src/libsystemd-network/sd-dhcp6-client.c b/src/libsystemd-network/sd-dhcp6-client.c
index 463fde401c..e81215f7d7 100644
--- a/src/libsystemd-network/sd-dhcp6-client.c
+++ b/src/libsystemd-network/sd-dhcp6-client.c
@@ -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) {
diff --git a/src/libsystemd-network/sd-dhcp6-lease.c b/src/libsystemd-network/sd-dhcp6-lease.c
index 5c10a6326a..ab59977a3f 100644
--- a/src/libsystemd-network/sd-dhcp6-lease.c
+++ b/src/libsystemd-network/sd-dhcp6-lease.c
@@ -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) {
diff --git a/src/libsystemd-network/sd-ipv4acd.c b/src/libsystemd-network/sd-ipv4acd.c
index 662885840f..4dd343c101 100644
--- a/src/libsystemd-network/sd-ipv4acd.c
+++ b/src/libsystemd-network/sd-ipv4acd.c
@@ -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) {
diff --git a/src/libsystemd-network/sd-ipv4ll.c b/src/libsystemd-network/sd-ipv4ll.c
index 5603a533a5..13209261f9 100644
--- a/src/libsystemd-network/sd-ipv4ll.c
+++ b/src/libsystemd-network/sd-ipv4ll.c
@@ -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) {
diff --git a/src/libsystemd-network/sd-lldp.c b/src/libsystemd-network/sd-lldp.c
index 0bd1e66aa0..0702241506 100644
--- a/src/libsystemd-network/sd-lldp.c
+++ b/src/libsystemd-network/sd-lldp.c
@@ -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) {
diff --git a/src/libsystemd-network/sd-ndisc.c b/src/libsystemd-network/sd-ndisc.c
index 07b0d7f704..1d3be9b862 100644
--- a/src/libsystemd-network/sd-ndisc.c
+++ b/src/libsystemd-network/sd-ndisc.c
@@ -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) {
diff --git a/src/libsystemd/sd-bus/bus-slot.c b/src/libsystemd/sd-bus/bus-slot.c
index 8e9074c7df..33590c31ac 100644
--- a/src/libsystemd/sd-bus/bus-slot.c
+++ b/src/libsystemd/sd-bus/bus-slot.c
@@ -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) {
diff --git a/src/libsystemd/sd-bus/bus-track.c b/src/libsystemd/sd-bus/bus-track.c
index 00e93a215f..4acaf24793 100644
--- a/src/libsystemd/sd-bus/bus-track.c
+++ b/src/libsystemd/sd-bus/bus-track.c
@@ -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) {
diff --git a/src/libudev/libudev-list.c b/src/libudev/libudev-list.c
index da496ed456..0d51322a15 100644
--- a/src/libudev/libudev-list.c
+++ b/src/libudev/libudev-list.c
@@ -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;
diff --git a/src/libudev/libudev-monitor.c b/src/libudev/libudev-monitor.c
index 1f9d16c450..a1f2b33ad5 100644
--- a/src/libudev/libudev-monitor.c
+++ b/src/libudev/libudev-monitor.c
@@ -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;
diff --git a/src/login/loginctl.c b/src/login/loginctl.c
index 0fc33cf541..4c618ed19e 100644
--- a/src/login/loginctl.c
+++ b/src/login/loginctl.c
@@ -83,6 +83,34 @@ static OutputFlags get_output_flags(void) {
colors_enabled() * OUTPUT_COLOR;
}
+static int get_session_path(sd_bus *bus, const char *session_id, sd_bus_error *error, char **path) {
+ _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
+ int r;
+ char *ans;
+
+ r = sd_bus_call_method(
+ bus,
+ "org.freedesktop.login1",
+ "/org/freedesktop/login1",
+ "org.freedesktop.login1.Manager",
+ "GetSession",
+ error, &reply,
+ "s", session_id);
+ if (r < 0)
+ return r;
+
+ r = sd_bus_message_read(reply, "o", &ans);
+ if (r < 0)
+ return r;
+
+ ans = strdup(ans);
+ if (!ans)
+ return -ENOMEM;
+
+ *path = ans;
+ return 0;
+}
+
static int list_sessions(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
@@ -115,10 +143,38 @@ static int list_sessions(int argc, char *argv[], void *userdata) {
return bus_log_parse_error(r);
if (arg_legend)
- printf("%10s %10s %-16s %-16s\n", "SESSION", "UID", "USER", "SEAT");
+ printf("%10s %10s %-16s %-16s %-16s\n", "SESSION", "UID", "USER", "SEAT", "TTY");
while ((r = sd_bus_message_read(reply, "(susso)", &id, &uid, &user, &seat, &object)) > 0) {
- printf("%10s %10u %-16s %-16s\n", id, (unsigned) uid, user, seat);
+ _cleanup_(sd_bus_error_free) sd_bus_error error2 = SD_BUS_ERROR_NULL;
+ _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply2 = NULL;
+ _cleanup_free_ char *path = NULL;
+ const char *tty = NULL;
+
+ r = get_session_path(bus, id, &error2, &path);
+ if (r < 0)
+ log_warning("Failed to get session path: %s", bus_error_message(&error, r));
+ else {
+ r = sd_bus_get_property(
+ bus,
+ "org.freedesktop.login1",
+ path,
+ "org.freedesktop.login1.Session",
+ "TTY",
+ &error2,
+ &reply2,
+ "s");
+ if (r < 0)
+ log_warning("Failed to get TTY for session %s: %s",
+ id, bus_error_message(&error2, r));
+ else {
+ r = sd_bus_message_read(reply2, "s", &tty);
+ if (r < 0)
+ return bus_log_parse_error(r);
+ }
+ }
+
+ printf("%10s %10"PRIu32" %-16s %-16s %-16s\n", id, uid, user, seat, strna(tty));
k++;
}
if (r < 0)
@@ -165,7 +221,7 @@ static int list_users(int argc, char *argv[], void *userdata) {
printf("%10s %-16s\n", "UID", "USER");
while ((r = sd_bus_message_read(reply, "(uso)", &uid, &user, &object)) > 0) {
- printf("%10u %-16s\n", (unsigned) uid, user);
+ printf("%10"PRIu32" %-16s\n", uid, user);
k++;
}
if (r < 0)
@@ -462,9 +518,9 @@ static int print_session_status_info(sd_bus *bus, const char *path, bool *new_li
printf("%s - ", strna(i.id));
if (i.name)
- printf("%s (%u)\n", i.name, (unsigned) i.uid);
+ printf("%s (%"PRIu32")\n", i.name, i.uid);
else
- printf("%u\n", (unsigned) i.uid);
+ printf("%"PRIu32"\n", i.uid);
s1 = format_timestamp_relative(since1, sizeof(since1), i.timestamp.realtime);
s2 = format_timestamp(since2, sizeof(since2), i.timestamp.realtime);
@@ -477,7 +533,7 @@ static int print_session_status_info(sd_bus *bus, const char *path, bool *new_li
if (i.leader > 0) {
_cleanup_free_ char *t = NULL;
- printf("\t Leader: %u", (unsigned) i.leader);
+ printf("\t Leader: %"PRIu32, i.leader);
get_process_comm(i.leader, &t);
if (t)
@@ -589,9 +645,9 @@ static int print_user_status_info(sd_bus *bus, const char *path, bool *new_line)
*new_line = true;
if (i.name)
- printf("%s (%u)\n", i.name, (unsigned) i.uid);
+ printf("%s (%"PRIu32")\n", i.name, i.uid);
else
- printf("%u\n", (unsigned) i.uid);
+ printf("%"PRIu32"\n", i.uid);
s1 = format_timestamp_relative(since1, sizeof(since1), i.timestamp.realtime);
s2 = format_timestamp(since2, sizeof(since2), i.timestamp.realtime);
@@ -887,26 +943,14 @@ static int show_session(int argc, char *argv[], void *userdata) {
for (i = 1; i < argc; i++) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
- _cleanup_(sd_bus_message_unrefp) sd_bus_message * reply = NULL;
- const char *path = NULL;
+ _cleanup_free_ char *path = NULL;
- r = sd_bus_call_method(
- bus,
- "org.freedesktop.login1",
- "/org/freedesktop/login1",
- "org.freedesktop.login1.Manager",
- "GetSession",
- &error, &reply,
- "s", argv[i]);
+ r = get_session_path(bus, argv[1], &error, &path);
if (r < 0) {
- log_error("Failed to get session: %s", bus_error_message(&error, r));
+ log_error("Failed to get session path: %s", bus_error_message(&error, r));
return r;
}
- r = sd_bus_message_read(reply, "o", &path);
- if (r < 0)
- return bus_log_parse_error(r);
-
if (properties)
r = show_properties(bus, path, &new_line);
else
diff --git a/src/login/logind-button.c b/src/login/logind-button.c
index baa6b7113c..90fb93bbaf 100644
--- a/src/login/logind-button.c
+++ b/src/login/logind-button.c
@@ -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;
diff --git a/src/login/logind-device.c b/src/login/logind-device.c
index eb5edd1cd5..6537fa04bf 100644
--- a/src/login/logind-device.c
+++ b/src/login/logind-device.c
@@ -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;
diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c
index 6c78e0dddc..c93b24009b 100644
--- a/src/login/logind-inhibit.c
+++ b/src/login/logind-inhibit.c
@@ -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;
diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c
index b5192320e4..ecc7bd2e5b 100644
--- a/src/login/logind-seat.c
+++ b/src/login/logind-seat.c
@@ -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;
diff --git a/src/login/logind-session.c b/src/login/logind-session.c
index ba1bcc2630..cbf035f706 100644
--- a/src/login/logind-session.c
+++ b/src/login/logind-session.c
@@ -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;
diff --git a/src/machine/machine.c b/src/machine/machine.c
index dd046d6563..a02b9d7575 100644
--- a/src/machine/machine.c
+++ b/src/machine/machine.c
@@ -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) {
diff --git a/src/machine/operation.c b/src/machine/operation.c
index 2bf93cb493..c966d0d21c 100644
--- a/src/machine/operation.c
+++ b/src/machine/operation.c
@@ -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);
}
diff --git a/src/network/networkd-wait-online-link.c b/src/network/networkd-wait-online-link.c
index 5727422e3d..e63ba07e90 100644
--- a/src/network/networkd-wait-online-link.c
+++ b/src/network/networkd-wait-online-link.c
@@ -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) {
diff --git a/src/nspawn/nspawn-settings.c b/src/nspawn/nspawn-settings.c
index 5f1522cfb6..09c8f070ba 100644
--- a/src/nspawn/nspawn-settings.c
+++ b/src/nspawn/nspawn-settings.c
@@ -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) {
diff --git a/src/resolve/resolved-dns-query.c b/src/resolve/resolved-dns-query.c
index 53be18efc6..e03db4d003 100644
--- a/src/resolve/resolved-dns-query.c
+++ b/src/resolve/resolved-dns-query.c
@@ -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(
diff --git a/src/resolve/resolved-dns-rr.c b/src/resolve/resolved-dns-rr.c
index 5687588a7d..87e4abec6e 100644
--- a/src/resolve/resolved-dns-rr.c
+++ b/src/resolve/resolved-dns-rr.c
@@ -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) {
diff --git a/src/resolve/resolved-dns-scope.c b/src/resolve/resolved-dns-scope.c
index 03811ac8e7..8dbc7f623b 100644
--- a/src/resolve/resolved-dns-scope.c
+++ b/src/resolve/resolved-dns-scope.c
@@ -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) {
diff --git a/src/resolve/resolved-dns-search-domain.c b/src/resolve/resolved-dns-search-domain.c
index 732471027b..1386e6a17b 100644
--- a/src/resolve/resolved-dns-search-domain.c
+++ b/src/resolve/resolved-dns-search-domain.c
@@ -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) {
diff --git a/src/resolve/resolved-dns-server.c b/src/resolve/resolved-dns-server.c
index 97cc8c0e09..7282848e35 100644
--- a/src/resolve/resolved-dns-server.c
+++ b/src/resolve/resolved-dns-server.c
@@ -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) {
diff --git a/src/resolve/resolved-dns-stream.c b/src/resolve/resolved-dns-stream.c
index dd0e0b90e3..878bae47dc 100644
--- a/src/resolve/resolved-dns-stream.c
+++ b/src/resolve/resolved-dns-stream.c
@@ -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);
diff --git a/src/resolve/resolved-dns-transaction.c b/src/resolve/resolved-dns-transaction.c
index d455b6b1fa..2fce44ec8b 100644
--- a/src/resolve/resolved-dns-transaction.c
+++ b/src/resolve/resolved-dns-transaction.c
@@ -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);
diff --git a/src/resolve/resolved-link.c b/src/resolve/resolved-link.c
index ea4a007139..13e1f91192 100644
--- a/src/resolve/resolved-link.c
+++ b/src/resolve/resolved-link.c
@@ -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) {
diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c
index 40f08e8044..0954641c20 100644
--- a/src/resolve/resolved-manager.c
+++ b/src/resolve/resolved-manager.c
@@ -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) {
diff --git a/src/shared/install.c b/src/shared/install.c
index 60a6d1312d..f70b3e3dd5 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -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);
diff --git a/src/shared/machine-image.c b/src/shared/machine-image.c
index 529d89ee2a..060f8d50c7 100644
--- a/src/shared/machine-image.c
+++ b/src/shared/machine-image.c
@@ -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) {
diff --git a/src/shared/ptyfwd.c b/src/shared/ptyfwd.c
index 24055e772b..293c6673fc 100644
--- a/src/shared/ptyfwd.c
+++ b/src/shared/ptyfwd.c
@@ -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) {
diff --git a/src/timesync/timesyncd-server.c b/src/timesync/timesyncd-server.c
index 6bda86fe6e..57a7bf2c25 100644
--- a/src/timesync/timesyncd-server.c
+++ b/src/timesync/timesyncd-server.c
@@ -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) {
diff --git a/src/udev/udev-ctrl.c b/src/udev/udev-ctrl.c
index f68a09d7a8..7717ac7924 100644
--- a/src/udev/udev-ctrl.c
+++ b/src/udev/udev-ctrl.c
@@ -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) {
diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c
index 26fa52cf6c..7619c8371b 100644
--- a/src/udev/udev-rules.c
+++ b/src/udev/udev-rules.c
@@ -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) {