summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-04-05 14:26:26 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2018-04-05 14:26:26 +0900
commit1cc6c93a9569a9f2664d0d26cd0e50408307c430 (patch)
tree57e115a1beb9b097f731da79c3192015ff35cc94 /src
parent3d282fff063c81893dc4bbd0282193d20dd5357e (diff)
downloadsystemd-1cc6c93a9569a9f2664d0d26cd0e50408307c430.tar.gz
tree-wide: use TAKE_PTR() and TAKE_FD() macros
Diffstat (limited to 'src')
-rw-r--r--src/analyze/analyze.c3
-rw-r--r--src/basic/bpf-program.c4
-rw-r--r--src/basic/btrfs-util.c3
-rw-r--r--src/basic/cgroup-util.c3
-rw-r--r--src/basic/cpu-set-util.c6
-rw-r--r--src/basic/fileio.c3
-rw-r--r--src/basic/hexdecoct.c9
-rw-r--r--src/basic/khash.c3
-rw-r--r--src/basic/locale-util.c3
-rw-r--r--src/basic/set.c4
-rw-r--r--src/basic/socket-util.c3
-rw-r--r--src/basic/time-util.c3
-rw-r--r--src/busctl/busctl.c3
-rw-r--r--src/core/bpf-firewall.c3
-rw-r--r--src/core/dbus-timer.c6
-rw-r--r--src/core/dbus.c6
-rw-r--r--src/core/execute.c3
-rw-r--r--src/core/job.c6
-rw-r--r--src/core/load-dropin.c7
-rw-r--r--src/core/load-fragment.c20
-rw-r--r--src/core/main.c7
-rw-r--r--src/core/manager.c7
-rw-r--r--src/core/namespace.c13
-rw-r--r--src/core/service.c11
-rw-r--r--src/core/socket.c6
-rw-r--r--src/core/unit.c8
-rw-r--r--src/coredump/coredump-vacuum.c3
-rw-r--r--src/coredump/coredump.c20
-rw-r--r--src/coredump/coredumpctl.c3
-rw-r--r--src/hostname/hostnamed.c3
-rw-r--r--src/import/curl-util.c3
-rw-r--r--src/import/export-raw.c3
-rw-r--r--src/import/export-tar.c3
-rw-r--r--src/import/import-raw.c3
-rw-r--r--src/import/import-tar.c3
-rw-r--r--src/import/importd.c6
-rw-r--r--src/import/pull-common.c3
-rw-r--r--src/import/pull-job.c3
-rw-r--r--src/import/pull-raw.c3
-rw-r--r--src/import/pull-tar.c3
-rw-r--r--src/journal-remote/journal-remote.c4
-rw-r--r--src/journal-remote/microhttpd-util.c6
-rw-r--r--src/journal/journal-file.c3
-rw-r--r--src/journal/journal-vacuum.c3
-rw-r--r--src/journal/journalctl.c17
-rw-r--r--src/journal/journald-context.c7
-rw-r--r--src/libsystemd-network/lldp-neighbor.c3
-rw-r--r--src/libsystemd-network/ndisc-router.c6
-rw-r--r--src/libsystemd-network/sd-dhcp-client.c12
-rw-r--r--src/libsystemd-network/sd-dhcp-lease.c3
-rw-r--r--src/libsystemd-network/sd-dhcp-server.c6
-rw-r--r--src/libsystemd-network/sd-dhcp6-client.c3
-rw-r--r--src/libsystemd-network/sd-ipv4acd.c6
-rw-r--r--src/libsystemd-network/sd-ipv4ll.c3
-rw-r--r--src/libsystemd-network/sd-lldp.c3
-rw-r--r--src/libsystemd-network/sd-ndisc.c3
-rw-r--r--src/libsystemd-network/sd-radv.c14
-rw-r--r--src/libsystemd/sd-bus/bus-control.c19
-rw-r--r--src/libsystemd/sd-bus/bus-creds.c4
-rw-r--r--src/libsystemd/sd-bus/bus-match.c3
-rw-r--r--src/libsystemd/sd-bus/bus-message.c6
-rw-r--r--src/libsystemd/sd-bus/sd-bus.c13
-rw-r--r--src/libsystemd/sd-device/device-enumerator.c3
-rw-r--r--src/libsystemd/sd-device/device-private.c15
-rw-r--r--src/libsystemd/sd-device/sd-device.c12
-rw-r--r--src/libsystemd/sd-hwdb/sd-hwdb.c3
-rw-r--r--src/libsystemd/sd-login/sd-login.c18
-rw-r--r--src/libsystemd/sd-netlink/generic-netlink.c3
-rw-r--r--src/libsystemd/sd-netlink/local-addresses.c6
-rw-r--r--src/libsystemd/sd-netlink/netlink-message.c3
-rw-r--r--src/libsystemd/sd-netlink/netlink-socket.c11
-rw-r--r--src/libsystemd/sd-netlink/sd-netlink.c18
-rw-r--r--src/libudev/libudev-hwdb.c3
-rw-r--r--src/locale/keymap-util.c3
-rw-r--r--src/locale/localed.c3
-rw-r--r--src/login/logind-seat-dbus.c3
-rw-r--r--src/login/logind-session-dbus.c3
-rw-r--r--src/login/logind-user-dbus.c3
-rw-r--r--src/login/logind-user.c4
-rw-r--r--src/machine/image-dbus.c3
-rw-r--r--src/machine/machine-dbus.c9
-rw-r--r--src/machine/machined.c5
-rw-r--r--src/network/netdev/wireguard.c10
-rw-r--r--src/network/networkctl.c6
-rw-r--r--src/network/networkd-address-label.c12
-rw-r--r--src/network/networkd-address.c15
-rw-r--r--src/network/networkd-fdb.c6
-rw-r--r--src/network/networkd-link.c6
-rw-r--r--src/network/networkd-lldp-tx.c3
-rw-r--r--src/network/networkd-manager.c3
-rw-r--r--src/network/networkd-radv.c9
-rw-r--r--src/network/networkd-route.c15
-rw-r--r--src/network/networkd-routing-policy-rule.c6
-rw-r--r--src/network/wait-online/manager.c3
-rw-r--r--src/nspawn/nspawn-expose-ports.c3
-rw-r--r--src/nspawn/nspawn-mount.c17
-rw-r--r--src/nspawn/nspawn-patch-uid.c3
-rw-r--r--src/nspawn/nspawn-settings.c3
-rw-r--r--src/nspawn/nspawn-setuid.c6
-rw-r--r--src/nspawn/nspawn.c65
-rw-r--r--src/resolve/resolved-conf.c6
-rw-r--r--src/resolve/resolved-dns-answer.c12
-rw-r--r--src/resolve/resolved-dns-packet.c21
-rw-r--r--src/resolve/resolved-dns-query.c12
-rw-r--r--src/resolve/resolved-dns-question.c12
-rw-r--r--src/resolve/resolved-dns-rr.c6
-rw-r--r--src/resolve/resolved-dns-scope.c6
-rw-r--r--src/resolve/resolved-dns-stream.c3
-rw-r--r--src/resolve/resolved-dns-synthesize.c6
-rw-r--r--src/resolve/resolved-dns-transaction.c9
-rw-r--r--src/resolve/resolved-dns-trust-anchor.c6
-rw-r--r--src/resolve/resolved-dns-zone.c9
-rw-r--r--src/resolve/resolved-manager.c6
-rw-r--r--src/resolve/resolved-mdns.c3
-rw-r--r--src/rfkill/rfkill.c3
-rw-r--r--src/shared/acl-util.c15
-rw-r--r--src/shared/bus-unit-util.c3
-rw-r--r--src/shared/bus-util.c12
-rw-r--r--src/shared/cgroup-show.c6
-rw-r--r--src/shared/conf-parser.c3
-rw-r--r--src/shared/dissect-image.c54
-rw-r--r--src/shared/dns-domain.c42
-rw-r--r--src/shared/efivars.c16
-rw-r--r--src/shared/install.c6
-rw-r--r--src/shared/loop-util.c7
-rw-r--r--src/shared/machine-image.c3
-rw-r--r--src/shared/path-lookup.c45
-rw-r--r--src/shared/ptyfwd.c3
-rw-r--r--src/shared/seccomp-util.c3
-rw-r--r--src/systemctl/systemctl.c28
-rw-r--r--src/sysusers/sysusers.c46
-rw-r--r--src/sysv-generator/sysv-generator.c5
-rw-r--r--src/timedate/timedated.c3
-rw-r--r--src/timesync/timesyncd-manager.c6
-rw-r--r--src/udev/net/link-config.c3
-rw-r--r--src/udev/udevd.c6
136 files changed, 383 insertions, 736 deletions
diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c
index 74f4d545ea..a6c93841fb 100644
--- a/src/analyze/analyze.c
+++ b/src/analyze/analyze.c
@@ -491,8 +491,7 @@ static int acquire_host_info(sd_bus *bus, struct host_info **hi) {
if (r < 0)
return log_error_errno(r, "Failed to get host information from systemd: %s", bus_error_message(&error, r));
- *hi = host;
- host = NULL;
+ *hi = TAKE_PTR(host);
return 0;
}
diff --git a/src/basic/bpf-program.c b/src/basic/bpf-program.c
index a244742f91..2cff567dc9 100644
--- a/src/basic/bpf-program.c
+++ b/src/basic/bpf-program.c
@@ -42,8 +42,8 @@ int bpf_program_new(uint32_t prog_type, BPFProgram **ret) {
p->prog_type = prog_type;
p->kernel_fd = -1;
- *ret = p;
- p = NULL;
+ *ret = TAKE_PTR(p);
+
return 0;
}
diff --git a/src/basic/btrfs-util.c b/src/basic/btrfs-util.c
index 3d30497f74..8b7d51f85a 100644
--- a/src/basic/btrfs-util.c
+++ b/src/basic/btrfs-util.c
@@ -1841,8 +1841,7 @@ int btrfs_qgroup_find_parents(int fd, uint64_t qgroupid, uint64_t **ret) {
return 0;
}
- *ret = items;
- items = NULL;
+ *ret = TAKE_PTR(items);
return (int) n_items;
}
diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c
index 67e690d6f5..530ad136ba 100644
--- a/src/basic/cgroup-util.c
+++ b/src/basic/cgroup-util.c
@@ -2448,8 +2448,7 @@ int cg_kernel_controllers(Set **ret) {
return r;
}
- *ret = controllers;
- controllers = NULL;
+ *ret = TAKE_PTR(controllers);
return 0;
}
diff --git a/src/basic/cpu-set-util.c b/src/basic/cpu-set-util.c
index 9f0a61a18e..818cb38081 100644
--- a/src/basic/cpu-set-util.c
+++ b/src/basic/cpu-set-util.c
@@ -111,10 +111,8 @@ int parse_cpu_set_internal(
}
/* On success, sets *cpu_set and returns ncpus for the system. */
- if (c) {
- *cpu_set = c;
- c = NULL;
- }
+ if (c)
+ *cpu_set = TAKE_PTR(c);
return (int) ncpus;
}
diff --git a/src/basic/fileio.c b/src/basic/fileio.c
index f807842c31..d0cb033bbb 100644
--- a/src/basic/fileio.c
+++ b/src/basic/fileio.c
@@ -1606,8 +1606,7 @@ int read_line(FILE *f, size_t limit, char **ret) {
if (ret) {
buffer[n] = 0;
- *ret = buffer;
- buffer = NULL;
+ *ret = TAKE_PTR(buffer);
}
return (int) count;
diff --git a/src/basic/hexdecoct.c b/src/basic/hexdecoct.c
index 0764521b6f..7f8a74acf6 100644
--- a/src/basic/hexdecoct.c
+++ b/src/basic/hexdecoct.c
@@ -125,8 +125,7 @@ int unhexmem(const char *p, size_t l, void **mem, size_t *len) {
*z = 0;
- *mem = r;
- r = NULL;
+ *mem = TAKE_PTR(r);
*len = (l + 1) / 2;
return 0;
@@ -482,8 +481,7 @@ int unbase32hexmem(const char *p, size_t l, bool padding, void **mem, size_t *_l
*z = 0;
- *mem = r;
- r = NULL;
+ *mem = TAKE_PTR(r);
*_len = len;
return 0;
@@ -751,8 +749,7 @@ int unbase64mem(const char *p, size_t l, void **ret, size_t *ret_size) {
if (ret_size)
*ret_size = (size_t) (z - buf);
- *ret = buf;
- buf = NULL;
+ *ret = TAKE_PTR(buf);
return 0;
}
diff --git a/src/basic/khash.c b/src/basic/khash.c
index 6463faf3e1..b3e1dc4448 100644
--- a/src/basic/khash.c
+++ b/src/basic/khash.c
@@ -216,8 +216,7 @@ int khash_dup(khash *h, khash **ret) {
if (copy->fd < 0)
return -errno;
- *ret = copy;
- copy = NULL;
+ *ret = TAKE_PTR(copy);
return 0;
}
diff --git a/src/basic/locale-util.c b/src/basic/locale-util.c
index de3d7c8c89..2080be24be 100644
--- a/src/basic/locale-util.c
+++ b/src/basic/locale-util.c
@@ -196,8 +196,7 @@ int get_locales(char ***ret) {
strv_sort(l);
- *ret = l;
- l = NULL;
+ *ret = TAKE_PTR(l);
return 0;
}
diff --git a/src/basic/set.c b/src/basic/set.c
index e554e825eb..da2cc0fb4a 100644
--- a/src/basic/set.c
+++ b/src/basic/set.c
@@ -18,6 +18,7 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "alloc-util.h"
#include "set.h"
int set_make(Set **ret, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS, void *add, ...) {
@@ -55,8 +56,7 @@ int set_make(Set **ret, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS, vo
va_end(ap);
}
- *ret = s;
- s = NULL;
+ *ret = TAKE_PTR(s);
return 0;
}
diff --git a/src/basic/socket-util.c b/src/basic/socket-util.c
index fd26ae7137..1bfd125e01 100644
--- a/src/basic/socket-util.c
+++ b/src/basic/socket-util.c
@@ -1017,8 +1017,7 @@ int getpeergroups(int fd, gid_t **ret) {
if ((socklen_t) (int) n != n)
return -E2BIG;
- *ret = d;
- d = NULL;
+ *ret = TAKE_PTR(d);
return (int) n;
}
diff --git a/src/basic/time-util.c b/src/basic/time-util.c
index 4a341e208f..b99d257b77 100644
--- a/src/basic/time-util.c
+++ b/src/basic/time-util.c
@@ -1283,8 +1283,7 @@ int get_timezones(char ***ret) {
} else if (errno != ENOENT)
return -errno;
- *ret = zones;
- zones = NULL;
+ *ret = TAKE_PTR(zones);
return 0;
}
diff --git a/src/busctl/busctl.c b/src/busctl/busctl.c
index 2f9250e2ae..2ac6a07624 100644
--- a/src/busctl/busctl.c
+++ b/src/busctl/busctl.c
@@ -137,8 +137,7 @@ static int acquire_bus(bool set_monitor, sd_bus **ret) {
if (r < 0)
return log_error_errno(r, "Failed to connect to bus: %m");
- *ret = bus;
- bus = NULL;
+ *ret = TAKE_PTR(bus);
return 0;
}
diff --git a/src/core/bpf-firewall.c b/src/core/bpf-firewall.c
index 48666f64a2..d8ce21be2b 100644
--- a/src/core/bpf-firewall.c
+++ b/src/core/bpf-firewall.c
@@ -311,8 +311,7 @@ static int bpf_firewall_compile_bpf(
return r;
} while (false);
- *ret = p;
- p = NULL;
+ *ret = TAKE_PTR(p);
return 0;
}
diff --git a/src/core/dbus-timer.c b/src/core/dbus-timer.c
index 1eedf217fe..1fa19966c8 100644
--- a/src/core/dbus-timer.c
+++ b/src/core/dbus-timer.c
@@ -290,8 +290,7 @@ static int bus_timer_set_transient_property(
return -ENOMEM;
v->base = b;
- v->calendar_spec = c;
- c = NULL;
+ v->calendar_spec = TAKE_PTR(c);
LIST_PREPEND(value, t->values, v);
}
@@ -377,8 +376,7 @@ static int bus_timer_set_transient_property(
return -ENOMEM;
v->base = TIMER_CALENDAR;
- v->calendar_spec = c;
- c = NULL;
+ v->calendar_spec = TAKE_PTR(c);
LIST_PREPEND(value, t->values, v);
}
diff --git a/src/core/dbus.c b/src/core/dbus.c
index ace6ffa8cf..ca6b070637 100644
--- a/src/core/dbus.c
+++ b/src/core/dbus.c
@@ -914,8 +914,7 @@ int bus_init_api(Manager *m) {
if (r < 0)
return log_error_errno(r, "Failed to set up API bus: %m");
- m->api_bus = bus;
- bus = NULL;
+ m->api_bus = TAKE_PTR(bus);
r = manager_enqueue_sync_bus_names(m);
if (r < 0)
@@ -976,8 +975,7 @@ int bus_init_system(Manager *m) {
if (r < 0)
return log_error_errno(r, "Failed to set up system bus: %m");
- m->system_bus = bus;
- bus = NULL;
+ m->system_bus = TAKE_PTR(bus);
return 0;
}
diff --git a/src/core/execute.c b/src/core/execute.c
index 664a3b96f7..bfc72ed021 100644
--- a/src/core/execute.c
+++ b/src/core/execute.c
@@ -1757,9 +1757,8 @@ static int build_pass_environment(const ExecContext *c, char ***ret) {
if (!GREEDY_REALLOC(pass_env, n_bufsize, n_env + 2))
return -ENOMEM;
- pass_env[n_env++] = x;
+ pass_env[n_env++] = TAKE_PTR(x);
pass_env[n_env] = NULL;
- x = NULL;
}
*ret = TAKE_PTR(pass_env);
diff --git a/src/core/job.c b/src/core/job.c
index 1b3534a7a6..daa8b09616 100644
--- a/src/core/job.c
+++ b/src/core/job.c
@@ -1439,8 +1439,7 @@ int job_get_before(Job *j, Job*** ret) {
n = sort_job_list(list, n);
- *ret = list;
- list = NULL;
+ *ret = TAKE_PTR(list);
return (int) n;
}
@@ -1489,8 +1488,7 @@ int job_get_after(Job *j, Job*** ret) {
n = sort_job_list(list, n);
- *ret = list;
- list = NULL;
+ *ret = TAKE_PTR(list);
return (int) n;
}
diff --git a/src/core/load-dropin.c b/src/core/load-dropin.c
index 57ed686d1f..0702219f24 100644
--- a/src/core/load-dropin.c
+++ b/src/core/load-dropin.c
@@ -146,10 +146,9 @@ int unit_load_dropin(Unit *u) {
if (r <= 0)
return 0;
- if (!u->dropin_paths) {
- u->dropin_paths = l;
- l = NULL;
- } else {
+ if (!u->dropin_paths)
+ u->dropin_paths = TAKE_PTR(l);
+ else {
r = strv_extend_strv(&u->dropin_paths, l, true);
if (r < 0)
return log_oom();
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index 887eb1cf49..be4af94fc8 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -731,9 +731,9 @@ int config_parse_exec(
if (!GREEDY_REALLOC(n, nbufsize, nlen + 2))
return log_oom();
- n[nlen++] = resolved;
+
+ n[nlen++] = TAKE_PTR(resolved);
n[nlen] = NULL;
- resolved = NULL;
}
if (!n || !n[0]) {
@@ -747,15 +747,13 @@ int config_parse_exec(
if (!nce)
return log_oom();
- nce->argv = n;
- nce->path = path;
+ nce->argv = TAKE_PTR(n);
+ nce->path = TAKE_PTR(path);
nce->flags = flags;
exec_command_append_list(e, nce);
/* Do not _cleanup_free_ these. */
- n = NULL;
- path = NULL;
nce = NULL;
rvalue = p;
@@ -2397,9 +2395,8 @@ int config_parse_pass_environ(
if (!GREEDY_REALLOC(n, nbufsize, nlen + 2))
return log_oom();
- n[nlen++] = k;
+ n[nlen++] = TAKE_PTR(k);
n[nlen] = NULL;
- k = NULL;
}
if (n) {
@@ -2474,9 +2471,8 @@ int config_parse_unset_environ(
if (!GREEDY_REALLOC(n, nbufsize, nlen + 2))
return log_oom();
- n[nlen++] = k;
+ n[nlen++] = TAKE_PTR(k);
n[nlen] = NULL;
- k = NULL;
}
if (n) {
@@ -4762,9 +4758,7 @@ static int load_from_path(Unit *u, const char *path) {
return r;
}
- free(u->fragment_path);
- u->fragment_path = filename;
- filename = NULL;
+ free_and_replace(u->fragment_path, filename);
if (u->source_path) {
if (stat(u->source_path, &st) >= 0)
diff --git a/src/core/main.c b/src/core/main.c
index 9e95b6f110..b0090e7e52 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -1131,11 +1131,8 @@ static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool switching
if (r < 0)
return log_error_errno(r, "Failed to disable O_CLOEXEC for serialization fds: %m");
- *_f = f;
- *_fds = fds;
-
- f = NULL;
- fds = NULL;
+ *_f = TAKE_PTR(f);
+ *_fds = TAKE_PTR(fds);
return 0;
}
diff --git a/src/core/manager.c b/src/core/manager.c
index e67f7446c7..ff6761e161 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -800,8 +800,8 @@ int manager_new(UnitFileScope scope, unsigned test_run_flags, Manager **_m) {
/* Note that we do not set up the notify fd here. We do that after deserialization,
* since they might have gotten serialized across the reexec. */
- *_m = m;
- m = NULL;
+ *_m = TAKE_PTR(m);
+
return 0;
}
@@ -1894,8 +1894,7 @@ int manager_get_dump_string(Manager *m, char **ret) {
f = safe_fclose(f);
- *ret = dump;
- dump = NULL;
+ *ret = TAKE_PTR(dump);
return 0;
}
diff --git a/src/core/namespace.c b/src/core/namespace.c
index a11c8e0147..1aba9022be 100644
--- a/src/core/namespace.c
+++ b/src/core/namespace.c
@@ -1395,14 +1395,13 @@ int bind_mount_add(BindMount **b, unsigned *n, const BindMount *item) {
*b = c;
c[(*n) ++] = (BindMount) {
- .source = s,
- .destination = d,
+ .source = TAKE_PTR(s),
+ .destination = TAKE_PTR(d),
.read_only = item->read_only,
.recursive = item->recursive,
.ignore_enoent = item->ignore_enoent,
};
- s = d = NULL;
return 0;
}
@@ -1449,11 +1448,10 @@ int temporary_filesystem_add(
*t = c;
c[(*n) ++] = (TemporaryFileSystem) {
- .path = p,
- .options = o,
+ .path = TAKE_PTR(p),
+ .options = TAKE_PTR(o),
};
- p = o = NULL;
return 0;
}
@@ -1491,8 +1489,7 @@ static int setup_one_tmp_dir(const char *id, const char *prefix, char **path) {
return -errno;
}
- *path = x;
- x = NULL;
+ *path = TAKE_PTR(x);
return 0;
}
diff --git a/src/core/service.c b/src/core/service.c
index a39c95da55..bd1851ac97 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -1250,10 +1250,8 @@ static int service_collect_fds(Service *s,
continue;
if (!rfds) {
- rfds = cfds;
+ rfds = TAKE_PTR(cfds);
rn_socket_fds = cn_fds;
-
- cfds = NULL;
} else {
int *t;
@@ -1305,14 +1303,11 @@ static int service_collect_fds(Service *s,
rfd_names[n_fds] = NULL;
}
- *fds = rfds;
- *fd_names = rfd_names;
+ *fds = TAKE_PTR(rfds);
+ *fd_names = TAKE_PTR(rfd_names);
*n_socket_fds = rn_socket_fds;
*n_storage_fds = rn_storage_fds;
- rfds = NULL;
- rfd_names = NULL;
-
return 0;
}
diff --git a/src/core/socket.c b/src/core/socket.c
index 6410939dca..d9a951b07f 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -629,8 +629,7 @@ int socket_acquire_peer(Socket *s, int fd, SocketPeer **p) {
remote->socket = s;
- *p = remote;
- remote = NULL;
+ *p = TAKE_PTR(remote);
return 1;
}
@@ -2365,8 +2364,7 @@ static void socket_enter_running(Socket *s, int cfd) {
cfd = -1; /* We passed ownership of the fd to the service now. Forget it here. */
s->n_connections++;
- service->peer = p; /* Pass ownership of the peer reference */
- p = NULL;
+ service->peer = TAKE_PTR(p); /* Pass ownership of the peer reference */
r = manager_add_job(UNIT(s)->manager, JOB_START, UNIT(service), JOB_REPLACE, &error, NULL);
if (r < 0) {
diff --git a/src/core/unit.c b/src/core/unit.c
index 72f475ab14..9ee50d3882 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -139,8 +139,8 @@ int unit_new_for_name(Manager *m, size_t size, const char *name, Unit **ret) {
if (r < 0)
return r;
- *ret = u;
- u = NULL;
+ *ret = TAKE_PTR(u);
+
return r;
}
@@ -266,13 +266,11 @@ int unit_add_name(Unit *u, const char *text) {
if (u->type == _UNIT_TYPE_INVALID) {
u->type = t;
u->id = s;
- u->instance = i;
+ u->instance = TAKE_PTR(i);
LIST_PREPEND(units_by_type, u->manager->units_by_type[t], u);
unit_init(u);
-
- i = NULL;
}
s = NULL;
diff --git a/src/coredump/coredump-vacuum.c b/src/coredump/coredump-vacuum.c
index e27512167c..d7ecf85bbf 100644
--- a/src/coredump/coredump-vacuum.c
+++ b/src/coredump/coredump-vacuum.c
@@ -227,8 +227,7 @@ int coredump_vacuum(int exclude_fd, uint64_t keep_free, uint64_t max_use) {
if (r < 0)
return log_oom();
- c = n;
- n = NULL;
+ c = TAKE_PTR(n);
}
c->n_files++;
diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c
index 6fbfe58bd6..6a10fd1e06 100644
--- a/src/coredump/coredump.c
+++ b/src/coredump/coredump.c
@@ -432,14 +432,11 @@ static int save_external_coredump(
if (tmp)
unlink_noerrno(tmp);
- *ret_filename = fn_compressed; /* compressed */
- *ret_node_fd = fd_compressed; /* compressed */
- *ret_data_fd = fd; /* uncompressed */
+ *ret_filename = TAKE_PTR(fn_compressed); /* compressed */
+ *ret_node_fd = TAKE_FD(fd_compressed); /* compressed */
+ *ret_data_fd = TAKE_FD(fd); /* uncompressed */
*ret_size = (uint64_t) st.st_size; /* uncompressed */
- fn_compressed = NULL;
- fd = fd_compressed = -1;
-
return 0;
fail_compressed:
@@ -454,14 +451,11 @@ uncompressed:
if (r < 0)
goto fail;
- *ret_filename = fn;
- *ret_data_fd = fd;
+ *ret_filename = TAKE_PTR(fn);
+ *ret_data_fd = TAKE_FD(fd);
*ret_node_fd = -1;
*ret_size = (uint64_t) st.st_size;
- fn = NULL;
- fd = -1;
-
return 0;
fail:
@@ -497,11 +491,9 @@ static int allocate_journal_field(int fd, size_t size, char **ret, size_t *ret_s
return -EIO;
}
- *ret = field;
+ *ret = TAKE_PTR(field);
*ret_size = size + 9;
- field = NULL;
-
return 0;
}
diff --git a/src/coredump/coredumpctl.c b/src/coredump/coredumpctl.c
index b0a00cda37..d2e23de7aa 100644
--- a/src/coredump/coredumpctl.c
+++ b/src/coredump/coredumpctl.c
@@ -146,8 +146,7 @@ static int acquire_journal(sd_journal **ret, char **matches) {
log_debug("Journal filter: %s", filter);
}
- *ret = j;
- j = NULL;
+ *ret = TAKE_PTR(j);
return 0;
}
diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c
index 1c8c76934c..370bd61486 100644
--- a/src/hostname/hostnamed.c
+++ b/src/hostname/hostnamed.c
@@ -688,8 +688,7 @@ static int connect_bus(Context *c, sd_event *event, sd_bus **_bus) {
if (r < 0)
return log_error_errno(r, "Failed to attach bus to event loop: %m");
- *_bus = bus;
- bus = NULL;
+ *_bus = TAKE_PTR(bus);
return 0;
}
diff --git a/src/import/curl-util.c b/src/import/curl-util.c
index 62bbaa500d..94315f1f7b 100644
--- a/src/import/curl-util.c
+++ b/src/import/curl-util.c
@@ -272,8 +272,7 @@ int curl_glue_new(CurlGlue **glue, sd_event *event) {
if (curl_multi_setopt(g->curl, CURLMOPT_TIMERFUNCTION, curl_glue_timer_callback) != CURLM_OK)
return -EINVAL;
- *glue = g;
- g = NULL;
+ *glue = TAKE_PTR(g);
return 0;
}
diff --git a/src/import/export-raw.c b/src/import/export-raw.c
index 9cab838b96..bdad19f1ea 100644
--- a/src/import/export-raw.c
+++ b/src/import/export-raw.c
@@ -122,8 +122,7 @@ int raw_export_new(
return r;
}
- *ret = e;
- e = NULL;
+ *ret = TAKE_PTR(e);
return 0;
}
diff --git a/src/import/export-tar.c b/src/import/export-tar.c
index dafe3e1c88..ef444008d9 100644
--- a/src/import/export-tar.c
+++ b/src/import/export-tar.c
@@ -126,8 +126,7 @@ int tar_export_new(
return r;
}
- *ret = e;
- e = NULL;
+ *ret = TAKE_PTR(e);
return 0;
}
diff --git a/src/import/import-raw.c b/src/import/import-raw.c
index 032b3dcda2..7f6a720274 100644
--- a/src/import/import-raw.c
+++ b/src/import/import-raw.c
@@ -141,8 +141,7 @@ int raw_import_new(
return r;
}
- *ret = i;
- i = NULL;
+ *ret = TAKE_PTR(i);
return 0;
}
diff --git a/src/import/import-tar.c b/src/import/import-tar.c
index 09c7654adc..1c03308628 100644
--- a/src/import/import-tar.c
+++ b/src/import/import-tar.c
@@ -148,8 +148,7 @@ int tar_import_new(
return r;
}
- *ret = i;
- i = NULL;
+ *ret = TAKE_PTR(i);
return 0;
}
diff --git a/src/import/importd.c b/src/import/importd.c
index 55e61b485f..220ac7e795 100644
--- a/src/import/importd.c
+++ b/src/import/importd.c
@@ -187,8 +187,7 @@ static int transfer_new(Manager *m, Transfer **ret) {
t->manager = m;
t->id = id;
- *ret = t;
- t = NULL;
+ *ret = TAKE_PTR(t);
return 0;
}
@@ -639,8 +638,7 @@ static int manager_new(Manager **ret) {
if (r < 0)
return r;
- *ret = m;
- m = NULL;
+ *ret = TAKE_PTR(m);
return 0;
}
diff --git a/src/import/pull-common.c b/src/import/pull-common.c
index 92f2692c81..dcd07d49b2 100644
--- a/src/import/pull-common.c
+++ b/src/import/pull-common.c
@@ -258,8 +258,7 @@ int pull_make_auxiliary_job(
job->on_finished = on_finished;
job->compressed_max = job->uncompressed_max = 1ULL * 1024ULL * 1024ULL;
- *ret = job;
- job = NULL;
+ *ret = TAKE_PTR(job);
return 0;
}
diff --git a/src/import/pull-job.c b/src/import/pull-job.c
index 2b71766798..0d5f2d2086 100644
--- a/src/import/pull-job.c
+++ b/src/import/pull-job.c
@@ -581,8 +581,7 @@ int pull_job_new(PullJob **ret, const char *url, CurlGlue *glue, void *userdata)
if (!j->url)
return -ENOMEM;
- *ret = j;
- j = NULL;
+ *ret = TAKE_PTR(j);
return 0;
}
diff --git a/src/import/pull-raw.c b/src/import/pull-raw.c
index 9784141871..ce0dea43a5 100644
--- a/src/import/pull-raw.c
+++ b/src/import/pull-raw.c
@@ -166,8 +166,7 @@ int raw_pull_new(
i->glue->on_finished = pull_job_curl_on_finished;
i->glue->userdata = i;
- *ret = i;
- i = NULL;
+ *ret = TAKE_PTR(i);
return 0;
}
diff --git a/src/import/pull-tar.c b/src/import/pull-tar.c
index 6ee63bdad5..10772fbaca 100644
--- a/src/import/pull-tar.c
+++ b/src/import/pull-tar.c
@@ -159,8 +159,7 @@ int tar_pull_new(
i->glue->on_finished = pull_job_curl_on_finished;
i->glue->userdata = i;
- *ret = i;
- i = NULL;
+ *ret = TAKE_PTR(i);
return 0;
}
diff --git a/src/journal-remote/journal-remote.c b/src/journal-remote/journal-remote.c
index ff46023920..da52e5b86e 100644
--- a/src/journal-remote/journal-remote.c
+++ b/src/journal-remote/journal-remote.c
@@ -259,8 +259,8 @@ static int get_writer(RemoteServer *s, const char *host,
return r;
}
- *writer = w;
- w = NULL;
+ *writer = TAKE_PTR(w);
+
return 0;
}
diff --git a/src/journal-remote/microhttpd-util.c b/src/journal-remote/microhttpd-util.c
index 2466c4f2b5..fe588eddfb 100644
--- a/src/journal-remote/microhttpd-util.c
+++ b/src/journal-remote/microhttpd-util.c
@@ -314,10 +314,8 @@ int check_permissions(struct MHD_Connection *connection, int *code, char **hostn
log_debug("Connection from %s", buf);
- if (hostname) {
- *hostname = buf;
- buf = NULL;
- }
+ if (hostname)
+ *hostname = TAKE_PTR(buf);
r = verify_cert_authorized(session);
if (r < 0) {
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index eab78074b5..3ea44128b1 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -1939,8 +1939,7 @@ int journal_file_enable_post_change_timer(JournalFile *f, sd_event *e, usec_t t)
if (r < 0)
return r;
- f->post_change_timer = timer;
- timer = NULL;
+ f->post_change_timer = TAKE_PTR(timer);
f->post_change_timer_period = t;
return r;
diff --git a/src/journal/journal-vacuum.c b/src/journal/journal-vacuum.c
index db36a6ab80..d6d8ccf75c 100644
--- a/src/journal/journal-vacuum.c
+++ b/src/journal/journal-vacuum.c
@@ -299,7 +299,7 @@ int journal_directory_vacuum(
goto finish;
}
- list[n_list].filename = p;
+ list[n_list].filename = TAKE_PTR(p);
list[n_list].usage = size;
list[n_list].seqnum = seqnum;
list[n_list].realtime = realtime;
@@ -307,7 +307,6 @@ int journal_directory_vacuum(
list[n_list].have_seqnum = have_seqnum;
n_list++;
- p = NULL;
sum += size;
}
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index fa2127c2b6..bcb75befe1 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -921,10 +921,9 @@ static int parse_argv(int argc, char *argv[]) {
if (!v)
return log_oom();
- if (!arg_output_fields) {
- arg_output_fields = v;
- v = NULL;
- } else {
+ if (!arg_output_fields)
+ arg_output_fields = TAKE_PTR(v);
+ else {
r = strv_extend_strv(&arg_output_fields, v, true);
if (r < 0)
return log_oom();
@@ -1229,8 +1228,7 @@ static int discover_next_boot(sd_journal *j,
if (r < 0)
return r;
- *ret = next_boot;
- next_boot = NULL;
+ *ret = TAKE_PTR(next_boot);
return 0;
}
@@ -1342,8 +1340,7 @@ static int get_boots(
}
}
LIST_INSERT_AFTER(boot_list, head, tail, current);
- tail = current;
- current = NULL;
+ tail = TAKE_PTR(current);
count++;
}
}
@@ -1508,8 +1505,8 @@ static int get_possible_units(
}
}
- *units = found;
- found = NULL;
+ *units = TAKE_PTR(found);
+
return 0;
}
diff --git a/src/journal/journald-context.c b/src/journal/journald-context.c
index f5345e4cb2..19e802d7c8 100644
--- a/src/journal/journald-context.c
+++ b/src/journal/journald-context.c
@@ -439,14 +439,11 @@ static int client_context_read_extra_fields(
free(c->extra_fields_iovec);
free(c->extra_fields_data);
- c->extra_fields_iovec = iovec;
+ c->extra_fields_iovec = TAKE_PTR(iovec);
c->extra_fields_n_iovec = n_iovec;
- c->extra_fields_data = data;
+ c->extra_fields_data = TAKE_PTR(data);
c->extra_fields_mtime = timespec_load_nsec(&st.st_mtim);
- iovec = NULL;
- data = NULL;
-
return 0;
}
diff --git a/src/libsystemd-network/lldp-neighbor.c b/src/libsystemd-network/lldp-neighbor.c
index 1a6ea288aa..84231091d0 100644
--- a/src/libsystemd-network/lldp-neighbor.c
+++ b/src/libsystemd-network/lldp-neighbor.c
@@ -674,8 +674,7 @@ _public_ int sd_lldp_neighbor_from_raw(sd_lldp_neighbor **ret, const void *raw,
if (r < 0)
return r;
- *ret = n;
- n = NULL;
+ *ret = TAKE_PTR(n);
return r;
}
diff --git a/src/libsystemd-network/ndisc-router.c b/src/libsystemd-network/ndisc-router.c
index 2954928d00..4584f59d1e 100644
--- a/src/libsystemd-network/ndisc-router.c
+++ b/src/libsystemd-network/ndisc-router.c
@@ -82,8 +82,7 @@ _public_ int sd_ndisc_router_from_raw(sd_ndisc_router **ret, const void *raw, si
if (r < 0)
return r;
- *ret = rt;
- rt = NULL;
+ *ret = TAKE_PTR(rt);
return r;
}
@@ -765,8 +764,7 @@ _public_ int sd_ndisc_router_dnssl_get_domains(sd_ndisc_router *rt, char ***ret)
return 0;
}
- *ret = l;
- l = NULL;
+ *ret = TAKE_PTR(l);
return k;
}
diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c
index 9cf49747e0..a8b0a81484 100644
--- a/src/libsystemd-network/sd-dhcp-client.c
+++ b/src/libsystemd-network/sd-dhcp-client.c
@@ -682,8 +682,7 @@ static int client_message_init(
*_optlen = optlen;
*_optoffset = optoffset;
- *ret = packet;
- packet = NULL;
+ *ret = TAKE_PTR(packet);
return 0;
}
@@ -1288,8 +1287,7 @@ static int client_handle_offer(sd_dhcp_client *client, DHCPMessage *offer, size_
}
sd_dhcp_lease_unref(client->lease);
- client->lease = lease;
- lease = NULL;
+ client->lease = TAKE_PTR(lease);
log_dhcp_client(client, "OFFER");
@@ -1370,8 +1368,7 @@ static int client_handle_ack(sd_dhcp_client *client, DHCPMessage *ack, size_t le
client->lease = sd_dhcp_lease_unref(client->lease);
}
- client->lease = lease;
- lease = NULL;
+ client->lease = TAKE_PTR(lease);
log_dhcp_client(client, "ACK");
@@ -1966,8 +1963,7 @@ int sd_dhcp_client_new(sd_dhcp_client **ret, int anonymize) {
if (!client->req_opts)
return -ENOMEM;
- *ret = client;
- client = NULL;
+ *ret = TAKE_PTR(client);
return 0;
}
diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c
index 9db0a93898..d33e208a00 100644
--- a/src/libsystemd-network/sd-dhcp-lease.c
+++ b/src/libsystemd-network/sd-dhcp-lease.c
@@ -1235,8 +1235,7 @@ int dhcp_lease_load(sd_dhcp_lease **ret, const char *lease_file) {
return r;
}
- *ret = lease;
- lease = NULL;
+ *ret = TAKE_PTR(lease);
return 0;
}
diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c
index 25f5b378bc..e88dcd0ac7 100644
--- a/src/libsystemd-network/sd-dhcp-server.c
+++ b/src/libsystemd-network/sd-dhcp-server.c
@@ -213,8 +213,7 @@ int sd_dhcp_server_new(sd_dhcp_server **ret, int ifindex) {
server->default_lease_time = DIV_ROUND_UP(DHCP_DEFAULT_LEASE_TIME_USEC, USEC_PER_SEC);
server->max_lease_time = DIV_ROUND_UP(DHCP_MAX_LEASE_TIME_USEC, USEC_PER_SEC);
- *ret = server;
- server = NULL;
+ *ret = TAKE_PTR(server);
return 0;
}
@@ -446,8 +445,7 @@ static int server_message_init(sd_dhcp_server *server, DHCPPacket **ret,
memcpy(&packet->dhcp.chaddr, &req->message->chaddr, ETH_ALEN);
*_optoffset = optoffset;
- *ret = packet;
- packet = NULL;
+ *ret = TAKE_PTR(packet);
return 0;
}
diff --git a/src/libsystemd-network/sd-dhcp6-client.c b/src/libsystemd-network/sd-dhcp6-client.c
index 056bfa3d3d..ff88c2bca9 100644
--- a/src/libsystemd-network/sd-dhcp6-client.c
+++ b/src/libsystemd-network/sd-dhcp6-client.c
@@ -1466,8 +1466,7 @@ int sd_dhcp6_client_new(sd_dhcp6_client **ret) {
for (t = 0; t < client->req_opts_len; t++)
client->req_opts[t] = htobe16(default_req_opts[t]);
- *ret = client;
- client = NULL;
+ *ret = TAKE_PTR(client);
return 0;
}
diff --git a/src/libsystemd-network/sd-ipv4acd.c b/src/libsystemd-network/sd-ipv4acd.c
index 7cf4f031de..ff36f3eec1 100644
--- a/src/libsystemd-network/sd-ipv4acd.c
+++ b/src/libsystemd-network/sd-ipv4acd.c
@@ -153,8 +153,7 @@ int sd_ipv4acd_new(sd_ipv4acd **ret) {
acd->ifindex = -1;
acd->fd = -1;
- *ret = acd;
- acd = NULL;
+ *ret = TAKE_PTR(acd);
return 0;
}
@@ -207,8 +206,7 @@ static int ipv4acd_set_next_wakeup(sd_ipv4acd *acd, usec_t usec, usec_t random_u
(void) sd_event_source_set_description(timer, "ipv4acd-timer");
sd_event_source_unref(acd->timer_event_source);
- acd->timer_event_source = timer;
- timer = NULL;
+ acd->timer_event_source = TAKE_PTR(timer);
return 0;
}
diff --git a/src/libsystemd-network/sd-ipv4ll.c b/src/libsystemd-network/sd-ipv4ll.c
index f3d09eb30a..0ac4c88255 100644
--- a/src/libsystemd-network/sd-ipv4ll.c
+++ b/src/libsystemd-network/sd-ipv4ll.c
@@ -115,8 +115,7 @@ int sd_ipv4ll_new(sd_ipv4ll **ret) {
if (r < 0)
return r;
- *ret = ll;
- ll = NULL;
+ *ret = TAKE_PTR(ll);
return 0;
}
diff --git a/src/libsystemd-network/sd-lldp.c b/src/libsystemd-network/sd-lldp.c
index 2c05416184..54b5e975ad 100644
--- a/src/libsystemd-network/sd-lldp.c
+++ b/src/libsystemd-network/sd-lldp.c
@@ -402,8 +402,7 @@ _public_ int sd_lldp_new(sd_lldp **ret) {
if (r < 0)
return r;
- *ret = lldp;
- lldp = NULL;
+ *ret = TAKE_PTR(lldp);
return 0;
}
diff --git a/src/libsystemd-network/sd-ndisc.c b/src/libsystemd-network/sd-ndisc.c
index b5c6d6e84d..c17df429c1 100644
--- a/src/libsystemd-network/sd-ndisc.c
+++ b/src/libsystemd-network/sd-ndisc.c
@@ -166,8 +166,7 @@ _public_ int sd_ndisc_new(sd_ndisc **ret) {
nd->n_ref = 1;
nd->fd = -1;
- *ret = nd;
- nd = NULL;
+ *ret = TAKE_PTR(nd);
return 0;
}
diff --git a/src/libsystemd-network/sd-radv.c b/src/libsystemd-network/sd-radv.c
index f30d6164ea..06fc0fb746 100644
--- a/src/libsystemd-network/sd-radv.c
+++ b/src/libsystemd-network/sd-radv.c
@@ -51,8 +51,7 @@ _public_ int sd_radv_new(sd_radv **ret) {
LIST_HEAD_INIT(ra->prefixes);
- *ret = ra;
- ra = NULL;
+ *ret = TAKE_PTR(ra);
return 0;
}
@@ -670,9 +669,7 @@ _public_ int sd_radv_set_rdnss(sd_radv *ra, uint32_t lifetime,
memcpy(opt_rdnss + 1, dns, n_dns * sizeof(struct in6_addr));
- free(ra->rdnss);
- ra->rdnss = opt_rdnss;
- opt_rdnss = NULL;
+ free_and_replace(ra->rdnss, opt_rdnss);
ra->n_rdnss = n_dns;
@@ -724,9 +721,7 @@ _public_ int sd_radv_set_dnssl(sd_radv *ra, uint32_t lifetime,
len -= r;
}
- free(ra->dnssl);
- ra->dnssl = opt_dnssl;
- opt_dnssl = NULL;
+ free_and_replace(ra->dnssl, opt_dnssl);
return 0;
}
@@ -755,8 +750,7 @@ _public_ int sd_radv_prefix_new(sd_radv_prefix **ret) {
LIST_INIT(prefix, p);
- *ret = p;
- p = NULL;
+ *ret = TAKE_PTR(p);
return 0;
}
diff --git a/src/libsystemd/sd-bus/bus-control.c b/src/libsystemd/sd-bus/bus-control.c
index 9dd5274bf6..50f2b3fc1a 100644
--- a/src/libsystemd/sd-bus/bus-control.c
+++ b/src/libsystemd/sd-bus/bus-control.c
@@ -431,14 +431,11 @@ _public_ int sd_bus_list_names(sd_bus *bus, char ***acquired, char ***activatabl
if (r < 0)
return r;
- *activatable = y;
- y = NULL;
+ *activatable = TAKE_PTR(y);
}
- if (acquired) {
- *acquired = x;
- x = NULL;
- }
+ if (acquired)
+ *acquired = TAKE_PTR(x);
return 0;
}
@@ -734,10 +731,8 @@ _public_ int sd_bus_get_name_creds(
return r;
}
- if (creds) {
- *creds = c;
- c = NULL;
- }
+ if (creds)
+ *creds = TAKE_PTR(c);
return 0;
}
@@ -810,8 +805,8 @@ _public_ int sd_bus_get_owner_creds(sd_bus *bus, uint64_t mask, sd_bus_creds **r
if (r < 0)
return r;
- *ret = c;
- c = NULL;
+ *ret = TAKE_PTR(c);
+
return 0;
}
diff --git a/src/libsystemd/sd-bus/bus-creds.c b/src/libsystemd/sd-bus/bus-creds.c
index b6ef4a0fe5..945d428c99 100644
--- a/src/libsystemd/sd-bus/bus-creds.c
+++ b/src/libsystemd/sd-bus/bus-creds.c
@@ -1344,7 +1344,7 @@ int bus_creds_extend_by_pid(sd_bus_creds *c, uint64_t mask, sd_bus_creds **ret)
if (r < 0)
return r;
- *ret = n;
- n = NULL;
+ *ret = TAKE_PTR(n);
+
return 0;
}
diff --git a/src/libsystemd/sd-bus/bus-match.c b/src/libsystemd/sd-bus/bus-match.c
index 8d798c0a58..03073d8647 100644
--- a/src/libsystemd/sd-bus/bus-match.c
+++ b/src/libsystemd/sd-bus/bus-match.c
@@ -903,11 +903,10 @@ int bus_match_parse(
}
components[n_components].type = t;
- components[n_components].value_str = value;
+ components[n_components].value_str = TAKE_PTR(value);
components[n_components].value_u8 = u;
n_components++;
- value = NULL;
if (q[quoted] == 0)
break;
diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c
index c76f6e87ba..af0050becb 100644
--- a/src/libsystemd/sd-bus/bus-message.c
+++ b/src/libsystemd/sd-bus/bus-message.c
@@ -513,8 +513,7 @@ int bus_message_from_header(
}
m->bus = sd_bus_ref(bus);
- *ret = m;
- m = NULL;
+ *ret = TAKE_PTR(m);
return 0;
}
@@ -5869,8 +5868,7 @@ int bus_message_remarshal(sd_bus *bus, sd_bus_message **m) {
return r;
sd_bus_message_unref(*m);
- *m = n;
- n = NULL;
+ *m = TAKE_PTR(n);
return 0;
}
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
index 36c866cd8f..c5df7ee6e4 100644
--- a/src/libsystemd/sd-bus/sd-bus.c
+++ b/src/libsystemd/sd-bus/sd-bus.c
@@ -524,8 +524,7 @@ static int synthesize_connected_signal(sd_bus *bus) {
/* Insert at the very front */
memmove(bus->rqueue + 1, bus->rqueue, sizeof(sd_bus_message*) * bus->rqueue_size);
- bus->rqueue[0] = m;
- m = NULL;
+ bus->rqueue[0] = TAKE_PTR(m);
bus->rqueue_size++;
return 0;
@@ -2775,8 +2774,8 @@ static int process_running(sd_bus *bus, bool hint_priority, int64_t priority, sd
if (r < 0)
return r;
- *ret = m;
- m = NULL;
+ *ret = TAKE_PTR(m);
+
return 1;
}
@@ -2935,10 +2934,8 @@ static int process_closing(sd_bus *bus, sd_bus_message **ret) {
bus->exit_triggered = true;
(void) bus_exit_now(bus);
- if (ret) {
- *ret = m;
- m = NULL;
- }
+ if (ret)
+ *ret = TAKE_PTR(m);
r = 1;
diff --git a/src/libsystemd/sd-device/device-enumerator.c b/src/libsystemd/sd-device/device-enumerator.c
index cd9ec042bf..3b90bc8383 100644
--- a/src/libsystemd/sd-device/device-enumerator.c
+++ b/src/libsystemd/sd-device/device-enumerator.c
@@ -71,8 +71,7 @@ _public_ int sd_device_enumerator_new(sd_device_enumerator **ret) {
enumerator->n_ref = 1;
enumerator->type = _DEVICE_ENUMERATION_TYPE_INVALID;
- *ret = enumerator;
- enumerator = NULL;
+ *ret = TAKE_PTR(enumerator);
return 0;
}
diff --git a/src/libsystemd/sd-device/device-private.c b/src/libsystemd/sd-device/device-private.c
index 77f0f4b2ee..19bb20fb9b 100644
--- a/src/libsystemd/sd-device/device-private.c
+++ b/src/libsystemd/sd-device/device-private.c
@@ -586,8 +586,7 @@ int device_new_from_strv(sd_device **ret, char **strv) {
if (r < 0)
return r;
- *ret = device;
- device = NULL;
+ *ret = TAKE_PTR(device);
return 0;
}
@@ -635,8 +634,7 @@ int device_new_from_nulstr(sd_device **ret, uint8_t *nulstr, size_t len) {
if (r < 0)
return r;
- *ret = device;
- device = NULL;
+ *ret = TAKE_PTR(device);
return 0;
}
@@ -812,8 +810,7 @@ int device_shallow_clone(sd_device *old_device, sd_device **new_device) {
ret->devnum = old_device->devnum;
- *new_device = ret;
- ret = NULL;
+ *new_device = TAKE_PTR(ret);
return 0;
}
@@ -835,8 +832,7 @@ int device_clone_with_db(sd_device *old_device, sd_device **new_device) {
ret->sealed = true;
- *new_device = ret;
- ret = NULL;
+ *new_device = TAKE_PTR(ret);
return 0;
}
@@ -861,8 +857,7 @@ int device_new_from_synthetic_event(sd_device **new_device, const char *syspath,
if (r < 0)
return r;
- *new_device = ret;
- ret = NULL;
+ *new_device = TAKE_PTR(ret);
return 0;
}
diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c
index 0273ec3d0e..c0a276ba68 100644
--- a/src/libsystemd/sd-device/sd-device.c
+++ b/src/libsystemd/sd-device/sd-device.c
@@ -46,7 +46,7 @@
#include "util.h"
int device_new_aux(sd_device **ret) {
- _cleanup_(sd_device_unrefp) sd_device *device = NULL;
+ sd_device *device = NULL;
assert(ret);
@@ -58,7 +58,6 @@ int device_new_aux(sd_device **ret) {
device->watch_handle = -1;
*ret = device;
- device = NULL;
return 0;
}
@@ -247,8 +246,7 @@ _public_ int sd_device_new_from_syspath(sd_device **ret, const char *syspath) {
if (r < 0)
return r;
- *ret = device;
- device = NULL;
+ *ret = TAKE_PTR(device);
return 0;
}
@@ -659,8 +657,7 @@ _public_ int sd_device_new_from_device_id(sd_device **ret, const char *id) {
if (ifr.ifr_ifindex != ifindex)
return -ENODEV;
- *ret = device;
- device = NULL;
+ *ret = TAKE_PTR(device);
return 0;
}
@@ -1833,8 +1830,7 @@ _public_ int sd_device_get_sysattr_value(sd_device *device, const char *sysattr,
if (r < 0)
return r;
- *_value = value;
- value = NULL;
+ *_value = TAKE_PTR(value);
return 0;
}
diff --git a/src/libsystemd/sd-hwdb/sd-hwdb.c b/src/libsystemd/sd-hwdb/sd-hwdb.c
index 9418e8cf38..4b66159790 100644
--- a/src/libsystemd/sd-hwdb/sd-hwdb.c
+++ b/src/libsystemd/sd-hwdb/sd-hwdb.c
@@ -373,8 +373,7 @@ _public_ int sd_hwdb_new(sd_hwdb **ret) {
log_debug("strings %8"PRIu64" bytes", le64toh(hwdb->head->strings_len));
log_debug("nodes %8"PRIu64" bytes", le64toh(hwdb->head->nodes_len));
- *ret = hwdb;
- hwdb = NULL;
+ *ret = TAKE_PTR(hwdb);
return 0;
}
diff --git a/src/libsystemd/sd-login/sd-login.c b/src/libsystemd/sd-login/sd-login.c
index 2a4eede9f8..d12d9dc6cf 100644
--- a/src/libsystemd/sd-login/sd-login.c
+++ b/src/libsystemd/sd-login/sd-login.c
@@ -741,15 +741,11 @@ _public_ int sd_seat_get_sessions(const char *seat, char ***sessions, uid_t **ui
r = strv_length(a);
- if (sessions) {
- *sessions = a;
- a = NULL;
- }
+ if (sessions)
+ *sessions = TAKE_PTR(a);
- if (uids) {
- *uids = b;
- b = NULL;
- }
+ if (uids)
+ *uids = TAKE_PTR(b);
if (n_uids)
*n_uids = n;
@@ -864,10 +860,8 @@ _public_ int sd_get_uids(uid_t **users) {
r++;
}
- if (users) {
- *users = l;
- l = NULL;
- }
+ if (users)
+ *users = TAKE_PTR(l);
return r;
}
diff --git a/src/libsystemd/sd-netlink/generic-netlink.c b/src/libsystemd/sd-netlink/generic-netlink.c
index 771658d9ae..347bf4cbd5 100644
--- a/src/libsystemd/sd-netlink/generic-netlink.c
+++ b/src/libsystemd/sd-netlink/generic-netlink.c
@@ -58,8 +58,7 @@ static int genl_message_new(sd_netlink *nl, sd_genl_family family, uint16_t nlms
genl->cmd = cmd;
genl->version = genl_families[family].version;
- *ret = m;
- m = NULL;
+ *ret = TAKE_PTR(m);
return 0;
}
diff --git a/src/libsystemd/sd-netlink/local-addresses.c b/src/libsystemd/sd-netlink/local-addresses.c
index 81e55b6d9f..ff9d605ae3 100644
--- a/src/libsystemd/sd-netlink/local-addresses.c
+++ b/src/libsystemd/sd-netlink/local-addresses.c
@@ -158,8 +158,7 @@ int local_addresses(sd_netlink *context, int ifindex, int af, struct local_addre
qsort_safe(list, n_list, sizeof(struct local_address), address_compare);
- *ret = list;
- list = NULL;
+ *ret = TAKE_PTR(list);
return (int) n_list;
}
@@ -271,8 +270,7 @@ int local_gateways(sd_netlink *context, int ifindex, int af, struct local_addres
if (n_list > 0)
qsort(list, n_list, sizeof(struct local_address), address_compare);
- *ret = list;
- list = NULL;
+ *ret = TAKE_PTR(list);
return (int) n_list;
}
diff --git a/src/libsystemd/sd-netlink/netlink-message.c b/src/libsystemd/sd-netlink/netlink-message.c
index 3a5f9346aa..13d4f4d225 100644
--- a/src/libsystemd/sd-netlink/netlink-message.c
+++ b/src/libsystemd/sd-netlink/netlink-message.c
@@ -98,8 +98,7 @@ int message_new(sd_netlink *rtnl, sd_netlink_message **ret, uint16_t type) {
m->hdr->nlmsg_len = size;
m->hdr->nlmsg_type = type;
- *ret = m;
- m = NULL;
+ *ret = TAKE_PTR(m);
return 0;
}
diff --git a/src/libsystemd/sd-netlink/netlink-socket.c b/src/libsystemd/sd-netlink/netlink-socket.c
index 3474ad9ddb..7db9205d7d 100644
--- a/src/libsystemd/sd-netlink/netlink-socket.c
+++ b/src/libsystemd/sd-netlink/netlink-socket.c
@@ -433,8 +433,7 @@ int socket_read_message(sd_netlink *rtnl) {
/* push the message onto the multi-part message stack */
if (first)
m->next = first;
- first = m;
- m = NULL;
+ first = TAKE_PTR(m);
}
if (len > 0)
@@ -449,8 +448,7 @@ int socket_read_message(sd_netlink *rtnl) {
if (r < 0)
return r;
- rtnl->rqueue[rtnl->rqueue_size++] = first;
- first = NULL;
+ rtnl->rqueue[rtnl->rqueue_size++] = TAKE_PTR(first);
if (multi_part && (i < rtnl->rqueue_partial_size)) {
/* remove the message form the partial read queue */
@@ -464,15 +462,14 @@ int socket_read_message(sd_netlink *rtnl) {
/* we only got a partial multi-part message, push it on the
partial read queue */
if (i < rtnl->rqueue_partial_size)
- rtnl->rqueue_partial[i] = first;
+ rtnl->rqueue_partial[i] = TAKE_PTR(first);
else {
r = rtnl_rqueue_partial_make_room(rtnl);
if (r < 0)
return r;
- rtnl->rqueue_partial[rtnl->rqueue_partial_size++] = first;
+ rtnl->rqueue_partial[rtnl->rqueue_partial_size++] = TAKE_PTR(first);
}
- first = NULL;
return 0;
}
diff --git a/src/libsystemd/sd-netlink/sd-netlink.c b/src/libsystemd/sd-netlink/sd-netlink.c
index 116e287bb6..e8fc2644c5 100644
--- a/src/libsystemd/sd-netlink/sd-netlink.c
+++ b/src/libsystemd/sd-netlink/sd-netlink.c
@@ -62,8 +62,7 @@ static int sd_netlink_new(sd_netlink **ret) {
* responses with notifications from the kernel */
rtnl->serial = 1;
- *ret = rtnl;
- rtnl = NULL;
+ *ret = TAKE_PTR(rtnl);
return 0;
}
@@ -90,8 +89,7 @@ int sd_netlink_new_from_netlink(sd_netlink **ret, int fd) {
rtnl->fd = fd;
- *ret = rtnl;
- rtnl = NULL;
+ *ret = TAKE_PTR(rtnl);
return 0;
}
@@ -133,8 +131,7 @@ int sd_netlink_open_fd(sd_netlink **ret, int fd) {
return r;
}
- *ret = rtnl;
- rtnl = NULL;
+ *ret = TAKE_PTR(rtnl);
return 0;
}
@@ -425,8 +422,7 @@ static int process_running(sd_netlink *rtnl, sd_netlink_message **ret) {
}
if (ret) {
- *ret = m;
- m = NULL;
+ *ret = TAKE_PTR(m);
return 1;
}
@@ -669,10 +665,8 @@ int sd_netlink_call(sd_netlink *rtnl,
return 0;
}
- if (ret) {
- *ret = incoming;
- incoming = NULL;
- }
+ if (ret)
+ *ret = TAKE_PTR(incoming);
return 1;
}
diff --git a/src/libudev/libudev-hwdb.c b/src/libudev/libudev-hwdb.c
index d2665278c1..eb71e6ebde 100644
--- a/src/libudev/libudev-hwdb.c
+++ b/src/libudev/libudev-hwdb.c
@@ -73,8 +73,7 @@ _public_ struct udev_hwdb *udev_hwdb_new(struct udev *udev) {
}
hwdb->refcount = 1;
- hwdb->hwdb = hwdb_internal;
- hwdb_internal = NULL;
+ hwdb->hwdb = TAKE_PTR(hwdb_internal);
udev_list_init(udev, &hwdb->properties_list, true);
diff --git a/src/locale/keymap-util.c b/src/locale/keymap-util.c
index 393e9b5648..d997928202 100644
--- a/src/locale/keymap-util.c
+++ b/src/locale/keymap-util.c
@@ -666,8 +666,7 @@ int find_language_fallback(const char *lang, char **language) {
if (streq(lang, a[0])) {
assert(strv_length(a) == 2);
- *language = a[1];
- a[1] = NULL;
+ *language = TAKE_PTR(a[1]);
return 1;
}
}
diff --git a/src/locale/localed.c b/src/locale/localed.c
index 02f5e8c656..685c1f9f8d 100644
--- a/src/locale/localed.c
+++ b/src/locale/localed.c
@@ -660,8 +660,7 @@ static int connect_bus(Context *c, sd_event *event, sd_bus **_bus) {
if (r < 0)
return log_error_errno(r, "Failed to attach bus to event loop: %m");
- *_bus = bus;
- bus = NULL;
+ *_bus = TAKE_PTR(bus);
return 0;
}
diff --git a/src/login/logind-seat-dbus.c b/src/login/logind-seat-dbus.c
index 8e4e4efc81..0b2824ee21 100644
--- a/src/login/logind-seat-dbus.c
+++ b/src/login/logind-seat-dbus.c
@@ -419,8 +419,7 @@ int seat_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***
}
}
- *nodes = l;
- l = NULL;
+ *nodes = TAKE_PTR(l);
return 1;
}
diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c
index 8264a42fd4..8414c86a64 100644
--- a/src/login/logind-session-dbus.c
+++ b/src/login/logind-session-dbus.c
@@ -666,8 +666,7 @@ int session_node_enumerator(sd_bus *bus, const char *path, void *userdata, char
}
}
- *nodes = l;
- l = NULL;
+ *nodes = TAKE_PTR(l);
return 1;
}
diff --git a/src/login/logind-user-dbus.c b/src/login/logind-user-dbus.c
index d5d086cfe0..ef1fce8bd1 100644
--- a/src/login/logind-user-dbus.c
+++ b/src/login/logind-user-dbus.c
@@ -354,8 +354,7 @@ int user_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***
}
}
- *nodes = l;
- l = NULL;
+ *nodes = TAKE_PTR(l);
return 1;
}
diff --git a/src/login/logind-user.c b/src/login/logind-user.c
index 28574f49a2..cee8be657e 100644
--- a/src/login/logind-user.c
+++ b/src/login/logind-user.c
@@ -100,8 +100,8 @@ int user_new(User **out, Manager *m, uid_t uid, gid_t gid, const char *name) {
if (r < 0)
return r;
- *out = u;
- u = NULL;
+ *out = TAKE_PTR(u);
+
return 0;
}
diff --git a/src/machine/image-dbus.c b/src/machine/image-dbus.c
index 8ba1380c81..a0965dc6b4 100644
--- a/src/machine/image-dbus.c
+++ b/src/machine/image-dbus.c
@@ -507,8 +507,7 @@ int image_node_enumerator(sd_bus *bus, const char *path, void *userdata, char **
return r;
}
- *nodes = l;
- l = NULL;
+ *nodes = TAKE_PTR(l);
return 1;
}
diff --git a/src/machine/machine-dbus.c b/src/machine/machine-dbus.c
index e37797f46a..208d25b3b5 100644
--- a/src/machine/machine-dbus.c
+++ b/src/machine/machine-dbus.c
@@ -522,8 +522,7 @@ static int container_bus_new(Machine *m, sd_bus_error *error, sd_bus **ret) {
if (r < 0)
return r;
- *ret = bus;
- bus = NULL;
+ *ret = TAKE_PTR(bus);
break;
}
@@ -647,8 +646,7 @@ int bus_machine_method_open_shell(sd_bus_message *message, void *userdata, sd_bu
} else {
if (!path_is_absolute(path))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Specified path '%s' is not absolute", path);
- args = args_wire;
- args_wire = NULL;
+ args = TAKE_PTR(args_wire);
if (strv_isempty(args)) {
args = strv_free(args);
@@ -1506,8 +1504,7 @@ int machine_send_create_reply(Machine *m, sd_bus_error *error) {
if (!m->create_message)
return 0;
- c = m->create_message;
- m->create_message = NULL;
+ c = TAKE_PTR(m->create_message);
if (error)
return sd_bus_reply_method_error(c, error);
diff --git a/src/machine/machined.c b/src/machine/machined.c
index 9fb67882e1..54f8d836a2 100644
--- a/src/machine/machined.c
+++ b/src/machine/machined.c
@@ -124,9 +124,8 @@ static int manager_add_host_machine(Manager *m) {
t->leader = 1;
t->id = mid;
- t->root_directory = rd;
- t->unit = unit;
- rd = unit = NULL;
+ t->root_directory = TAKE_PTR(rd);
+ t->unit = TAKE_PTR(unit);
dual_timestamp_from_boottime_or_monotonic(&t->timestamp, 0);
diff --git a/src/network/netdev/wireguard.c b/src/network/netdev/wireguard.c
index 9025693f70..23db87a0d5 100644
--- a/src/network/netdev/wireguard.c
+++ b/src/network/netdev/wireguard.c
@@ -626,15 +626,11 @@ int config_parse_wireguard_endpoint(const char *unit,
if (!port)
return log_oom();
- endpoint->peer = peer;
- endpoint->host = host;
- endpoint->port = port;
+ endpoint->peer = TAKE_PTR(peer);
+ endpoint->host = TAKE_PTR(host);
+ endpoint->port = TAKE_PTR(port);
endpoint->netdev = netdev_ref(data);
LIST_PREPEND(endpoints, w->unresolved_endpoints, endpoint);
-
- peer = NULL;
- host = NULL;
- port = NULL;
endpoint = NULL;
return 0;
diff --git a/src/network/networkctl.c b/src/network/networkctl.c
index 362f671417..1c711fb075 100644
--- a/src/network/networkctl.c
+++ b/src/network/networkctl.c
@@ -210,8 +210,7 @@ static int acquire_link_info_strv(sd_netlink *rtnl, char **l, LinkInfo **ret) {
qsort_safe(links, c, sizeof(LinkInfo), link_info_compare);
- *ret = links;
- links = NULL;
+ *ret = TAKE_PTR(links);
return (int) c;
}
@@ -251,8 +250,7 @@ static int acquire_link_info_all(sd_netlink *rtnl, LinkInfo **ret) {
qsort_safe(links, c, sizeof(LinkInfo), link_info_compare);
- *ret = links;
- links = NULL;
+ *ret = TAKE_PTR(links);
return (int) c;
}
diff --git a/src/network/networkd-address-label.c b/src/network/networkd-address-label.c
index 4fd5fa4f58..ed360b3391 100644
--- a/src/network/networkd-address-label.c
+++ b/src/network/networkd-address-label.c
@@ -36,8 +36,7 @@ int address_label_new(AddressLabel **ret) {
if (!addrlabel)
return -ENOMEM;
- *ret = addrlabel;
- addrlabel = NULL;
+ *ret = TAKE_PTR(addrlabel);
return 0;
}
@@ -75,8 +74,7 @@ static int address_label_new_static(Network *network, const char *filename, unsi
label = hashmap_get(network->address_labels_by_section, n);
if (label) {
- *ret = label;
- label = NULL;
+ *ret = TAKE_PTR(label);
return 0;
}
@@ -85,8 +83,7 @@ static int address_label_new_static(Network *network, const char *filename, unsi
if (r < 0)
return r;
- label->section = n;
- n = NULL;
+ label->section = TAKE_PTR(n);
r = hashmap_put(network->address_labels_by_section, label->section, label);
if (r < 0)
@@ -96,8 +93,7 @@ static int address_label_new_static(Network *network, const char *filename, unsi
LIST_APPEND(labels, network->address_labels, label);
network->n_address_labels++;
- *ret = label;
- label = NULL;
+ *ret = TAKE_PTR(label);
return 0;
}
diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c
index 7e722b1a2e..a61ec276ba 100644
--- a/src/network/networkd-address.c
+++ b/src/network/networkd-address.c
@@ -48,8 +48,7 @@ int address_new(Address **ret) {
address->cinfo.ifa_prefered = CACHE_INFO_INFINITY_LIFE_TIME;
address->cinfo.ifa_valid = CACHE_INFO_INFINITY_LIFE_TIME;
- *ret = address;
- address = NULL;
+ *ret = TAKE_PTR(address);
return 0;
}
@@ -70,8 +69,7 @@ int address_new_static(Network *network, const char *filename, unsigned section_
address = hashmap_get(network->addresses_by_section, n);
if (address) {
- *ret = address;
- address = NULL;
+ *ret = TAKE_PTR(address);
return 0;
}
@@ -85,8 +83,7 @@ int address_new_static(Network *network, const char *filename, unsigned section_
return r;
if (filename) {
- address->section = n;
- n = NULL;
+ address->section = TAKE_PTR(n);
r = hashmap_put(network->addresses_by_section, address->section, address);
if (r < 0)
@@ -97,8 +94,7 @@ int address_new_static(Network *network, const char *filename, unsigned section_
LIST_APPEND(addresses, network->static_addresses, address);
network->n_static_addresses++;
- *ret = address;
- address = NULL;
+ *ret = TAKE_PTR(address);
return 0;
}
@@ -541,8 +537,7 @@ static int address_acquire(Link *link, Address *original, Address **ret) {
LIST_PREPEND(addresses, link->pool_addresses, na);
- *ret = na;
- na = NULL;
+ *ret = TAKE_PTR(na);
return 0;
}
diff --git a/src/network/networkd-fdb.c b/src/network/networkd-fdb.c
index 380581e09a..7fcf2a46fd 100644
--- a/src/network/networkd-fdb.c
+++ b/src/network/networkd-fdb.c
@@ -48,8 +48,7 @@ int fdb_entry_new_static(
if (section) {
fdb_entry = hashmap_get(network->fdb_entries_by_section, UINT_TO_PTR(section));
if (fdb_entry) {
- *ret = fdb_entry;
- fdb_entry = NULL;
+ *ret = TAKE_PTR(fdb_entry);
return 0;
}
@@ -85,8 +84,7 @@ int fdb_entry_new_static(
}
/* return allocated FDB structure. */
- *ret = fdb_entry;
- fdb_entry = NULL;
+ *ret = TAKE_PTR(fdb_entry);
return 0;
}
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 2f9f7ad9e9..fa72023c16 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -501,8 +501,7 @@ static int link_new(Manager *manager, sd_netlink_message *message, Link **ret) {
if (r < 0)
return r;
- *ret = link;
- link = NULL;
+ *ret = TAKE_PTR(link);
return 0;
}
@@ -2973,8 +2972,7 @@ network_file_fail:
route->lifetime = lifetime;
sd_event_source_unref(route->expire);
- route->expire = expire;
- expire = NULL;
+ route->expire = TAKE_PTR(expire);
}
}
diff --git a/src/network/networkd-lldp-tx.c b/src/network/networkd-lldp-tx.c
index b8d160a1f8..0645aa40e4 100644
--- a/src/network/networkd-lldp-tx.c
+++ b/src/network/networkd-lldp-tx.c
@@ -198,10 +198,9 @@ static int lldp_make_packet(
assert(p == (uint8_t*) packet + l);
- *ret = packet;
+ *ret = TAKE_PTR(packet);
*sz = l;
- packet = NULL;
return 0;
}
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index 1c519d8c49..ddebf386e7 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -1444,8 +1444,7 @@ int manager_new(Manager **ret, sd_event *event) {
(void) routing_policy_load_rules(m->state_file, &m->rules_saved);
- *ret = m;
- m = NULL;
+ *ret = TAKE_PTR(m);
return 0;
}
diff --git a/src/network/networkd-radv.c b/src/network/networkd-radv.c
index 1cc89f3b0a..f7e14c9655 100644
--- a/src/network/networkd-radv.c
+++ b/src/network/networkd-radv.c
@@ -149,8 +149,7 @@ int prefix_new_static(Network *network, const char *filename,
if (section_line) {
prefix = hashmap_get(network->prefixes_by_section, n);
if (prefix) {
- *ret = prefix;
- prefix = NULL;
+ *ret = TAKE_PTR(prefix);
return 0;
}
@@ -162,8 +161,7 @@ int prefix_new_static(Network *network, const char *filename,
return r;
if (filename) {
- prefix->section = n;
- n = NULL;
+ prefix->section = TAKE_PTR(n);
r = hashmap_put(network->prefixes_by_section, prefix->section,
prefix);
@@ -175,8 +173,7 @@ int prefix_new_static(Network *network, const char *filename,
LIST_APPEND(prefixes, network->static_prefixes, prefix);
network->n_static_prefixes++;
- *ret = prefix;
- prefix = NULL;
+ *ret = TAKE_PTR(prefix);
return 0;
}
diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c
index d25be44a10..709f90395c 100644
--- a/src/network/networkd-route.c
+++ b/src/network/networkd-route.c
@@ -76,8 +76,7 @@ int route_new(Route **ret) {
route->lifetime = USEC_INFINITY;
route->quickack = -1;
- *ret = route;
- route = NULL;
+ *ret = TAKE_PTR(route);
return 0;
}
@@ -98,8 +97,7 @@ int route_new_static(Network *network, const char *filename, unsigned section_li
route = hashmap_get(network->routes_by_section, n);
if (route) {
- *ret = route;
- route = NULL;
+ *ret = TAKE_PTR(route);
return 0;
}
@@ -115,8 +113,7 @@ int route_new_static(Network *network, const char *filename, unsigned section_li
route->protocol = RTPROT_STATIC;
if (filename) {
- route->section = n;
- n = NULL;
+ route->section = TAKE_PTR(n);
r = hashmap_put(network->routes_by_section, route->section, route);
if (r < 0)
@@ -127,8 +124,7 @@ int route_new_static(Network *network, const char *filename, unsigned section_li
LIST_PREPEND(routes, network->static_routes, route);
network->n_static_routes++;
- *ret = route;
- route = NULL;
+ *ret = TAKE_PTR(route);
return 0;
}
@@ -689,8 +685,7 @@ int route_configure(
}
sd_event_source_unref(route->expire);
- route->expire = expire;
- expire = NULL;
+ route->expire = TAKE_PTR(expire);
return 0;
}
diff --git a/src/network/networkd-routing-policy-rule.c b/src/network/networkd-routing-policy-rule.c
index d8f712c069..3cfff5743a 100644
--- a/src/network/networkd-routing-policy-rule.c
+++ b/src/network/networkd-routing-policy-rule.c
@@ -406,8 +406,7 @@ static int routing_policy_rule_new_static(Network *network, const char *filename
rule = hashmap_get(network->rules_by_section, n);
if (rule) {
- *ret = rule;
- rule = NULL;
+ *ret = TAKE_PTR(rule);
return 0;
}
@@ -427,8 +426,7 @@ static int routing_policy_rule_new_static(Network *network, const char *filename
LIST_APPEND(rules, network->rules, rule);
network->n_rules++;
- *ret = rule;
- rule = NULL;
+ *ret = TAKE_PTR(rule);
return 0;
}
diff --git a/src/network/wait-online/manager.c b/src/network/wait-online/manager.c
index 05f030dbe7..b7e53b1ed7 100644
--- a/src/network/wait-online/manager.c
+++ b/src/network/wait-online/manager.c
@@ -303,8 +303,7 @@ int manager_new(Manager **ret, char **interfaces, char **ignore, usec_t timeout)
if (r < 0)
return r;
- *ret = m;
- m = NULL;
+ *ret = TAKE_PTR(m);
return 0;
}
diff --git a/src/nspawn/nspawn-expose-ports.c b/src/nspawn/nspawn-expose-ports.c
index 98eb85081e..0e2da276e7 100644
--- a/src/nspawn/nspawn-expose-ports.c
+++ b/src/nspawn/nspawn-expose-ports.c
@@ -239,8 +239,7 @@ int expose_port_watch_rtnl(
if (r < 0)
return log_error_errno(r, "Failed to add to even loop: %m");
- *ret = rtnl;
- rtnl = NULL;
+ *ret = TAKE_PTR(rtnl);
return 0;
}
diff --git a/src/nspawn/nspawn-mount.c b/src/nspawn/nspawn-mount.c
index e32c6223d7..465b6f4c80 100644
--- a/src/nspawn/nspawn-mount.c
+++ b/src/nspawn/nspawn-mount.c
@@ -282,10 +282,9 @@ int tmpfs_mount_parse(CustomMount **l, unsigned *n, const char *s) {
if (!m)
return -ENOMEM;
- m->destination = path;
- m->options = opts;
+ m->destination = TAKE_PTR(path);
+ m->options = TAKE_PTR(opts);
- path = opts = NULL;
return 0;
}
@@ -341,14 +340,11 @@ int overlay_mount_parse(CustomMount **l, unsigned *n, const char *s, bool read_o
if (!m)
return -ENOMEM;
- m->destination = destination;
- m->source = upper;
- m->lower = lower;
+ m->destination = TAKE_PTR(destination);
+ m->source = TAKE_PTR(upper);
+ m->lower = TAKE_PTR(lower);
m->read_only = read_only;
- upper = destination = NULL;
- lower = NULL;
-
return 0;
}
@@ -867,8 +863,7 @@ static int get_process_controllers(Set **ret) {
return r;
}
- *ret = controllers;
- controllers = NULL;
+ *ret = TAKE_PTR(controllers);
return 0;
}
diff --git a/src/nspawn/nspawn-patch-uid.c b/src/nspawn/nspawn-patch-uid.c
index 7081ed0db2..7f3f0ee1fc 100644
--- a/src/nspawn/nspawn-patch-uid.c
+++ b/src/nspawn/nspawn-patch-uid.c
@@ -175,8 +175,7 @@ static int shift_acl(acl_t acl, uid_t shift, acl_t *ret) {
return -errno;
}
- *ret = copy;
- copy = NULL;
+ *ret = TAKE_PTR(copy);
return !!*ret;
}
diff --git a/src/nspawn/nspawn-settings.c b/src/nspawn/nspawn-settings.c
index a1518a6e81..997e44c429 100644
--- a/src/nspawn/nspawn-settings.c
+++ b/src/nspawn/nspawn-settings.c
@@ -75,8 +75,7 @@ int settings_load(FILE *f, const char *path, Settings **ret) {
if (s->userns_chown >= 0 && s->userns_mode == _USER_NAMESPACE_MODE_INVALID)
s->userns_mode = USER_NAMESPACE_NO;
- *ret = s;
- s = NULL;
+ *ret = TAKE_PTR(s);
return 0;
}
diff --git a/src/nspawn/nspawn-setuid.c b/src/nspawn/nspawn-setuid.c
index 80189ac6db..0756cc64e8 100644
--- a/src/nspawn/nspawn-setuid.c
+++ b/src/nspawn/nspawn-setuid.c
@@ -243,10 +243,8 @@ int change_uid_gid(const char *user, char **_home) {
if (setresuid(uid, uid, uid) < 0)
return log_error_errno(errno, "setresuid() failed: %m");
- if (_home) {
- *_home = home;
- home = NULL;
- }
+ if (_home)
+ *_home = TAKE_PTR(home);
return 0;
}
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 384b1ea5df..810f1247ea 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -3074,8 +3074,7 @@ static int load_settings(void) {
f = fopen(j, "re");
if (f) {
- p = j;
- j = NULL;
+ p = TAKE_PTR(j);
/* By default, we trust configuration from /etc and /run */
if (arg_settings_trusted < 0)
@@ -3130,8 +3129,7 @@ static int load_settings(void) {
arg_start_mode = settings->start_mode;
strv_free(arg_parameters);
- arg_parameters = settings->parameters;
- settings->parameters = NULL;
+ arg_parameters = TAKE_PTR(settings->parameters);
}
if ((arg_settings_mask & SETTING_PIVOT_ROOT) == 0 &&
@@ -3141,25 +3139,18 @@ static int load_settings(void) {
}
if ((arg_settings_mask & SETTING_WORKING_DIRECTORY) == 0 &&
- settings->working_directory) {
- free(arg_chdir);
- arg_chdir = settings->working_directory;
- settings->working_directory = NULL;
- }
+ settings->working_directory)
+ free_and_replace(arg_chdir, settings->working_directory);
if ((arg_settings_mask & SETTING_ENVIRONMENT) == 0 &&
settings->environment) {
strv_free(arg_setenv);
- arg_setenv = settings->environment;
- settings->environment = NULL;
+ arg_setenv = TAKE_PTR(settings->environment);
}
if ((arg_settings_mask & SETTING_USER) == 0 &&
- settings->user) {
- free(arg_user);
- arg_user = settings->user;
- settings->user = NULL;
- }
+ settings->user)
+ free_and_replace(arg_user, settings->user);
if ((arg_settings_mask & SETTING_CAPABILITY) == 0) {
uint64_t plus;
@@ -3209,10 +3200,8 @@ static int load_settings(void) {
log_warning("Ignoring TemporaryFileSystem=, Bind= and BindReadOnly= settings, file %s is not trusted.", p);
else {
custom_mount_free_all(arg_custom_mounts, arg_n_custom_mounts);
- arg_custom_mounts = settings->custom_mounts;
+ arg_custom_mounts = TAKE_PTR(settings->custom_mounts);
arg_n_custom_mounts = settings->n_custom_mounts;
-
- settings->custom_mounts = NULL;
settings->n_custom_mounts = 0;
}
}
@@ -3234,28 +3223,19 @@ static int load_settings(void) {
arg_private_network = settings_private_network(settings);
strv_free(arg_network_interfaces);
- arg_network_interfaces = settings->network_interfaces;
- settings->network_interfaces = NULL;
+ arg_network_interfaces = TAKE_PTR(settings->network_interfaces);
strv_free(arg_network_macvlan);
- arg_network_macvlan = settings->network_macvlan;
- settings->network_macvlan = NULL;
+ arg_network_macvlan = TAKE_PTR(settings->network_macvlan);
strv_free(arg_network_ipvlan);
- arg_network_ipvlan = settings->network_ipvlan;
- settings->network_ipvlan = NULL;
+ arg_network_ipvlan = TAKE_PTR(settings->network_ipvlan);
strv_free(arg_network_veth_extra);
- arg_network_veth_extra = settings->network_veth_extra;
- settings->network_veth_extra = NULL;
+ arg_network_veth_extra = TAKE_PTR(settings->network_veth_extra);
- free(arg_network_bridge);
- arg_network_bridge = settings->network_bridge;
- settings->network_bridge = NULL;
-
- free(arg_network_zone);
- arg_network_zone = settings->network_zone;
- settings->network_zone = NULL;
+ free_and_replace(arg_network_bridge, settings->network_bridge);
+ free_and_replace(arg_network_zone, settings->network_zone);
}
}
@@ -3266,8 +3246,7 @@ static int load_settings(void) {
log_warning("Ignoring Port= setting, file %s is not trusted.", p);
else {
expose_port_free_all(arg_expose_ports);
- arg_expose_ports = settings->expose_ports;
- settings->expose_ports = NULL;
+ arg_expose_ports = TAKE_PTR(settings->expose_ports);
}
}
@@ -3295,10 +3274,8 @@ static int load_settings(void) {
strv_free(arg_syscall_whitelist);
strv_free(arg_syscall_blacklist);
- arg_syscall_whitelist = settings->syscall_whitelist;
- arg_syscall_blacklist = settings->syscall_blacklist;
-
- settings->syscall_whitelist = settings->syscall_blacklist = NULL;
+ arg_syscall_whitelist = TAKE_PTR(settings->syscall_whitelist);
+ arg_syscall_blacklist = TAKE_PTR(settings->syscall_blacklist);
}
}
@@ -3917,9 +3894,7 @@ int main(int argc, char *argv[]) {
goto finish;
}
- free(arg_directory);
- arg_directory = np;
- np = NULL;
+ free_and_replace(arg_directory, np);
remove_directory = true;
@@ -4009,9 +3984,7 @@ int main(int argc, char *argv[]) {
goto finish;
}
- free(arg_image);
- arg_image = np;
- np = NULL;
+ free_and_replace(arg_image, np);
remove_image = true;
} else {
diff --git a/src/resolve/resolved-conf.c b/src/resolve/resolved-conf.c
index ca69d70e3c..bffdf9f32d 100644
--- a/src/resolve/resolved-conf.c
+++ b/src/resolve/resolved-conf.c
@@ -337,10 +337,8 @@ int config_parse_dnssd_txt(const char *unit, const char *filename, unsigned line
r = split_pair(word, "=", &key, &value);
if (r == -ENOMEM)
return log_oom();
- if (r == -EINVAL) {
- key = word;
- word = NULL;
- }
+ if (r == -EINVAL)
+ key = TAKE_PTR(word);
if (!ascii_is_valid(key)) {
log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid syntax, ignoring: %s", key);
diff --git a/src/resolve/resolved-dns-answer.c b/src/resolve/resolved-dns-answer.c
index ecc6143e62..394cb2c86e 100644
--- a/src/resolve/resolved-dns-answer.c
+++ b/src/resolve/resolved-dns-answer.c
@@ -442,8 +442,7 @@ int dns_answer_merge(DnsAnswer *a, DnsAnswer *b, DnsAnswer **ret) {
if (r < 0)
return r;
- *ret = k;
- k = NULL;
+ *ret = TAKE_PTR(k);
return 0;
}
@@ -518,8 +517,7 @@ int dns_answer_remove_by_key(DnsAnswer **a, const DnsResourceKey *key) {
}
dns_answer_unref(*a);
- *a = copy;
- copy = NULL;
+ *a = TAKE_PTR(copy);
return 1;
}
@@ -604,8 +602,7 @@ int dns_answer_remove_by_rr(DnsAnswer **a, DnsResourceRecord *rm) {
}
dns_answer_unref(*a);
- *a = copy;
- copy = NULL;
+ *a = TAKE_PTR(copy);
return 1;
}
@@ -778,8 +775,7 @@ int dns_answer_reserve_or_clone(DnsAnswer **a, unsigned n_free) {
return r;
dns_answer_unref(*a);
- *a = n;
- n = NULL;
+ *a = TAKE_PTR(n);
return 0;
}
diff --git a/src/resolve/resolved-dns-packet.c b/src/resolve/resolved-dns-packet.c
index 2067dd5182..5128763e99 100644
--- a/src/resolve/resolved-dns-packet.c
+++ b/src/resolve/resolved-dns-packet.c
@@ -1472,8 +1472,7 @@ int dns_packet_read_name(
if (after_rindex != 0)
p->rindex= after_rindex;
- *_ret = ret;
- ret = NULL;
+ *_ret = TAKE_PTR(ret);
if (start)
*start = rewinder.saved_rindex;
@@ -2084,8 +2083,7 @@ int dns_packet_read_rr(DnsPacket *p, DnsResourceRecord **ret, bool *ret_cache_fl
if (p->rindex != offset + rdlength)
return -EBADMSG;
- *ret = rr;
- rr = NULL;
+ *ret = TAKE_PTR(rr);
if (ret_cache_flush)
*ret_cache_flush = cache_flush;
@@ -2171,8 +2169,8 @@ static int dns_packet_extract_question(DnsPacket *p, DnsQuestion **ret_question)
}
}
- *ret_question = question;
- question = NULL;
+ *ret_question = TAKE_PTR(question);
+
return 0;
}
@@ -2287,8 +2285,8 @@ static int dns_packet_extract_answer(DnsPacket *p, DnsAnswer **ret_answer) {
if (bad_opt)
p->opt = dns_resource_record_unref(p->opt);
- *ret_answer = answer;
- answer = NULL;
+ *ret_answer = TAKE_PTR(answer);
+
return 0;
}
@@ -2312,11 +2310,8 @@ int dns_packet_extract(DnsPacket *p) {
if (r < 0)
return r;
- p->question = question;
- question = NULL;
-
- p->answer = answer;
- answer = NULL;
+ p->question = TAKE_PTR(question);
+ p->answer = TAKE_PTR(answer);
p->extracted = true;
diff --git a/src/resolve/resolved-dns-query.c b/src/resolve/resolved-dns-query.c
index 5f51340743..91a31c0ff5 100644
--- a/src/resolve/resolved-dns-query.c
+++ b/src/resolve/resolved-dns-query.c
@@ -638,8 +638,7 @@ static int dns_query_synthesize_reply(DnsQuery *q, DnsTransactionState *state) {
dns_query_reset_answer(q);
- q->answer = answer;
- answer = NULL;
+ q->answer = TAKE_PTR(answer);
q->answer_rcode = DNS_RCODE_SUCCESS;
q->answer_protocol = dns_synthesize_protocol(q->flags);
q->answer_family = dns_synthesize_family(q->flags);
@@ -668,8 +667,7 @@ static int dns_query_try_etc_hosts(DnsQuery *q) {
dns_query_reset_answer(q);
- q->answer = answer;
- answer = NULL;
+ q->answer = TAKE_PTR(answer);
q->answer_rcode = DNS_RCODE_SUCCESS;
q->answer_protocol = dns_synthesize_protocol(q->flags);
q->answer_family = dns_synthesize_family(q->flags);
@@ -994,12 +992,10 @@ static int dns_query_cname_redirect(DnsQuery *q, const DnsResourceRecord *cname)
q->flags |= SD_RESOLVED_NO_SEARCH;
dns_question_unref(q->question_idna);
- q->question_idna = nq_idna;
- nq_idna = NULL;
+ q->question_idna = TAKE_PTR(nq_idna);
dns_question_unref(q->question_utf8);
- q->question_utf8 = nq_utf8;
- nq_utf8 = NULL;
+ q->question_utf8 = TAKE_PTR(nq_utf8);
dns_query_free_candidates(q);
dns_query_reset_answer(q);
diff --git a/src/resolve/resolved-dns-question.c b/src/resolve/resolved-dns-question.c
index 4dc3de4052..89e7ca0150 100644
--- a/src/resolve/resolved-dns-question.c
+++ b/src/resolve/resolved-dns-question.c
@@ -278,8 +278,7 @@ int dns_question_cname_redirect(DnsQuestion *q, const DnsResourceRecord *cname,
return r;
}
- *ret = n;
- n = NULL;
+ *ret = TAKE_PTR(n);
return 1;
}
@@ -348,8 +347,7 @@ int dns_question_new_address(DnsQuestion **ret, int family, const char *name, bo
return r;
}
- *ret = q;
- q = NULL;
+ *ret = TAKE_PTR(q);
return 0;
}
@@ -384,8 +382,7 @@ int dns_question_new_reverse(DnsQuestion **ret, int family, const union in_addr_
if (r < 0)
return r;
- *ret = q;
- q = NULL;
+ *ret = TAKE_PTR(q);
return 0;
}
@@ -468,8 +465,7 @@ int dns_question_new_service(
return r;
}
- *ret = q;
- q = NULL;
+ *ret = TAKE_PTR(q);
return 0;
}
diff --git a/src/resolve/resolved-dns-rr.c b/src/resolve/resolved-dns-rr.c
index 4056bda558..f668284682 100644
--- a/src/resolve/resolved-dns-rr.c
+++ b/src/resolve/resolved-dns-rr.c
@@ -560,8 +560,7 @@ int dns_resource_record_new_reverse(DnsResourceRecord **ret, int family, const u
if (!rr->ptr.name)
return -ENOMEM;
- *ret = rr;
- rr = NULL;
+ *ret = TAKE_PTR(rr);
return 0;
}
@@ -1734,8 +1733,7 @@ DnsResourceRecord *dns_resource_record_copy(DnsResourceRecord *rr) {
break;
}
- t = copy;
- copy = NULL;
+ t = TAKE_PTR(copy);
return t;
}
diff --git a/src/resolve/resolved-dns-scope.c b/src/resolve/resolved-dns-scope.c
index 305bb6afe8..94f50dd134 100644
--- a/src/resolve/resolved-dns-scope.c
+++ b/src/resolve/resolved-dns-scope.c
@@ -681,8 +681,7 @@ int dns_scope_make_reply_packet(
return r;
DNS_PACKET_HEADER(p)->arcount = htobe16(dns_answer_size(soa));
- *ret = p;
- p = NULL;
+ *ret = TAKE_PTR(p);
return 0;
}
@@ -866,8 +865,7 @@ static int dns_scope_make_conflict_packet(
if (r < 0)
return r;
- *ret = p;
- p = NULL;
+ *ret = TAKE_PTR(p);
return 0;
}
diff --git a/src/resolve/resolved-dns-stream.c b/src/resolve/resolved-dns-stream.c
index 52f23cd864..50c7a4f4e2 100644
--- a/src/resolve/resolved-dns-stream.c
+++ b/src/resolve/resolved-dns-stream.c
@@ -399,8 +399,7 @@ int dns_stream_new(Manager *m, DnsStream **ret, DnsProtocol protocol, int fd) {
s->fd = fd;
m->n_dns_streams++;
- *ret = s;
- s = NULL;
+ *ret = TAKE_PTR(s);
return 0;
}
diff --git a/src/resolve/resolved-dns-synthesize.c b/src/resolve/resolved-dns-synthesize.c
index e71fcbdcca..a66f488dd6 100644
--- a/src/resolve/resolved-dns-synthesize.c
+++ b/src/resolve/resolved-dns-synthesize.c
@@ -440,10 +440,8 @@ int dns_synthesize_answer(
if (found) {
- if (ret) {
- *ret = answer;
- answer = NULL;
- }
+ if (ret)
+ *ret = TAKE_PTR(answer);
return 1;
} else if (nxdomain)
diff --git a/src/resolve/resolved-dns-transaction.c b/src/resolve/resolved-dns-transaction.c
index f4bbde0219..4eb4524219 100644
--- a/src/resolve/resolved-dns-transaction.c
+++ b/src/resolve/resolved-dns-transaction.c
@@ -1530,8 +1530,7 @@ static int dns_transaction_make_packet_mdns(DnsTransaction *t) {
}
DNS_PACKET_HEADER(p)->nscount = htobe16(nscount);
- t->sent = p;
- p = NULL;
+ t->sent = TAKE_PTR(p);
return 0;
}
@@ -1559,8 +1558,7 @@ static int dns_transaction_make_packet(DnsTransaction *t) {
DNS_PACKET_HEADER(p)->qdcount = htobe16(1);
DNS_PACKET_HEADER(p)->id = t->id;
- t->sent = p;
- p = NULL;
+ t->sent = TAKE_PTR(p);
return 0;
}
@@ -3079,8 +3077,7 @@ int dns_transaction_validate_dnssec(DnsTransaction *t) {
}
dns_answer_unref(t->answer);
- t->answer = validated;
- validated = NULL;
+ t->answer = TAKE_PTR(validated);
/* At this point the answer only contains validated
* RRsets. Now, let's see if it actually answers the question
diff --git a/src/resolve/resolved-dns-trust-anchor.c b/src/resolve/resolved-dns-trust-anchor.c
index c6e47ed0e9..fc7f26a46f 100644
--- a/src/resolve/resolved-dns-trust-anchor.c
+++ b/src/resolve/resolved-dns-trust-anchor.c
@@ -301,8 +301,7 @@ static int dns_trust_anchor_load_positive(DnsTrustAnchor *d, const char *path, u
rr->ds.algorithm = a;
rr->ds.digest_type = dt;
rr->ds.digest_size = l;
- rr->ds.digest = dd;
- dd = NULL;
+ rr->ds.digest = TAKE_PTR(dd);
} else if (strcaseeq(type, "DNSKEY")) {
_cleanup_free_ char *flags = NULL, *protocol = NULL, *algorithm = NULL, *key = NULL;
@@ -354,8 +353,7 @@ static int dns_trust_anchor_load_positive(DnsTrustAnchor *d, const char *path, u
rr->dnskey.protocol = 3;
rr->dnskey.algorithm = a;
rr->dnskey.key_size = l;
- rr->dnskey.key = k;
- k = NULL;
+ rr->dnskey.key = TAKE_PTR(k);
} else {
log_warning("RR type %s is not supported, ignoring line %s:%u.", type, path, line);
diff --git a/src/resolve/resolved-dns-zone.c b/src/resolve/resolved-dns-zone.c
index 4888eccbd3..b0f8bf0510 100644
--- a/src/resolve/resolved-dns-zone.c
+++ b/src/resolve/resolved-dns-zone.c
@@ -487,13 +487,10 @@ int dns_zone_lookup(DnsZone *z, DnsResourceKey *key, int ifindex, DnsAnswer **re
if (!ret_tentative && tentative)
goto return_empty;
- *ret_answer = answer;
- answer = NULL;
+ *ret_answer = TAKE_PTR(answer);
- if (ret_soa) {
- *ret_soa = soa;
- soa = NULL;
- }
+ if (ret_soa)
+ *ret_soa = TAKE_PTR(soa);
if (ret_tentative)
*ret_tentative = tentative;
diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c
index de1f0ce21d..3bb2ba3e35 100644
--- a/src/resolve/resolved-manager.c
+++ b/src/resolve/resolved-manager.c
@@ -646,8 +646,7 @@ int manager_new(Manager **ret) {
manager_cleanup_saved_user(m);
- *ret = m;
- m = NULL;
+ *ret = TAKE_PTR(m);
return 0;
}
@@ -855,8 +854,7 @@ int manager_recv(Manager *m, int fd, DnsProtocol protocol, DnsPacket **ret) {
p->ifindex = manager_find_ifindex(m, p->family, &p->destination);
}
- *ret = p;
- p = NULL;
+ *ret = TAKE_PTR(p);
return 1;
}
diff --git a/src/resolve/resolved-mdns.c b/src/resolve/resolved-mdns.c
index 38e2c54227..1fdb65352c 100644
--- a/src/resolve/resolved-mdns.c
+++ b/src/resolve/resolved-mdns.c
@@ -171,8 +171,7 @@ static int mdns_packet_extract_matching_rrs(DnsPacket *p, DnsResourceKey *key, D
assert(n == size);
qsort_safe(list, size, sizeof(DnsResourceRecord*), mdns_rr_compare);
- *ret_rrs = list;
- list = NULL;
+ *ret_rrs = TAKE_PTR(list);
return size;
}
diff --git a/src/rfkill/rfkill.c b/src/rfkill/rfkill.c
index ff951450b5..bae3aec175 100644
--- a/src/rfkill/rfkill.c
+++ b/src/rfkill/rfkill.c
@@ -319,10 +319,9 @@ static int save_state_queue(
if (!item)
return -ENOMEM;
- item->file = state_file;
+ item->file = TAKE_PTR(state_file);
item->rfkill_idx = event->idx;
item->state = event->soft;
- state_file = NULL;
LIST_APPEND(queue, *write_queue, item);
diff --git a/src/shared/acl-util.c b/src/shared/acl-util.c
index 889a971d88..25d48a5ffc 100644
--- a/src/shared/acl-util.c
+++ b/src/shared/acl-util.c
@@ -217,10 +217,8 @@ int acl_search_groups(const char *path, char ***ret_groups) {
r = acl_get_entry(acl, ACL_NEXT_ENTRY, &entry);
}
- if (ret_groups) {
- *ret_groups = g;
- g = NULL;
- }
+ if (ret_groups)
+ *ret_groups = TAKE_PTR(g);
return ret;
}
@@ -287,9 +285,8 @@ int parse_acl(const char *text, acl_t *acl_access, acl_t *acl_default, bool want
}
}
- *acl_access = a_acl;
- *acl_default = d_acl;
- a_acl = d_acl = NULL;
+ *acl_access = TAKE_PTR(a_acl);
+ *acl_default = TAKE_PTR(d_acl);
return 0;
}
@@ -393,8 +390,8 @@ int acls_for_file(const char *path, acl_type_t type, acl_t new, acl_t *acl) {
if (r < 0)
return -errno;
- *acl = old;
- old = NULL;
+ *acl = TAKE_PTR(old);
+
return 0;
}
diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c
index 8e1e16d73b..a9c17d29e2 100644
--- a/src/shared/bus-unit-util.c
+++ b/src/shared/bus-unit-util.c
@@ -1805,8 +1805,7 @@ int bus_wait_for_jobs_new(sd_bus *bus, BusWaitForJobs **ret) {
if (r < 0)
return r;
- *ret = d;
- d = NULL;
+ *ret = TAKE_PTR(d);
return 0;
}
diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c
index df382f77a6..d9cb33443f 100644
--- a/src/shared/bus-util.c
+++ b/src/shared/bus-util.c
@@ -604,8 +604,7 @@ int bus_connect_system_systemd(sd_bus **_bus) {
if (r < 0)
return r;
- *_bus = bus;
- bus = NULL;
+ *_bus = TAKE_PTR(bus);
return 0;
}
@@ -642,8 +641,7 @@ int bus_connect_user_systemd(sd_bus **_bus) {
if (r < 0)
return r;
- *_bus = bus;
- bus = NULL;
+ *_bus = TAKE_PTR(bus);
return 0;
}
@@ -1338,8 +1336,7 @@ int bus_connect_transport(BusTransport transport, const char *host, bool user, s
if (r < 0)
return r;
- *ret = bus;
- bus = NULL;
+ *ret = TAKE_PTR(bus);
return 0;
}
@@ -1718,8 +1715,7 @@ int bus_open_system_watch_bind(sd_bus **ret) {
if (r < 0)
return r;
- *ret = bus;
- bus = NULL;
+ *ret = TAKE_PTR(bus);
return 0;
}
diff --git a/src/shared/cgroup-show.c b/src/shared/cgroup-show.c
index 326a398075..ae2bfadffc 100644
--- a/src/shared/cgroup-show.c
+++ b/src/shared/cgroup-show.c
@@ -385,10 +385,8 @@ int show_cgroup_get_path_and_warn(
return log_oom();
*ret = t;
- } else {
- *ret = root;
- root = NULL;
- }
+ } else
+ *ret = TAKE_PTR(root);
return 0;
}
diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c
index 483dc1a69f..ad70166d68 100644
--- a/src/shared/conf-parser.c
+++ b/src/shared/conf-parser.c
@@ -1167,8 +1167,7 @@ int config_parse_join_controllers(
}
strv_free_free(*ret);
- *ret = controllers;
- controllers = NULL;
+ *ret = TAKE_PTR(controllers);
return 0;
}
diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c
index 95a98341ff..e2baa4497c 100644
--- a/src/shared/dissect-image.c
+++ b/src/shared/dissect-image.c
@@ -229,16 +229,13 @@ int dissect_image(
.rw = true,
.partno = -1,
.architecture = _ARCHITECTURE_INVALID,
- .fstype = t,
- .node = n,
+ .fstype = TAKE_PTR(t),
+ .node = TAKE_PTR(n),
};
- t = n = NULL;
-
m->encrypted = streq(fstype, "crypto_LUKS");
- *ret = m;
- m = NULL;
+ *ret = TAKE_PTR(m);
return 0;
}
@@ -541,12 +538,10 @@ int dissect_image(
.partno = nr,
.rw = rw,
.architecture = architecture,
- .node = n,
- .fstype = t,
+ .node = TAKE_PTR(n),
+ .fstype = TAKE_PTR(t),
.uuid = id,
};
-
- n = t = NULL;
}
} else if (is_mbr) {
@@ -604,11 +599,9 @@ int dissect_image(
.rw = generic_rw,
.partno = generic_nr,
.architecture = _ARCHITECTURE_INVALID,
- .node = generic_node,
+ .node = TAKE_PTR(generic_node),
.uuid = generic_uuid,
};
-
- generic_node = NULL;
}
}
@@ -651,8 +644,7 @@ int dissect_image(
p->rw = false;
}
- *ret = m;
- m = NULL;
+ *ret = TAKE_PTR(m);
return 0;
#else
@@ -883,10 +875,9 @@ static int make_dm_name_and_node(const void *original_node, const char *suffix,
if (!node)
return -ENOMEM;
- *ret_name = name;
- *ret_node = node;
+ *ret_name = TAKE_PTR(name);
+ *ret_node = TAKE_PTR(node);
- name = node = NULL;
return 0;
}
@@ -935,15 +926,11 @@ static int decrypt_partition(
return r == -EPERM ? -EKEYREJECTED : r;
}
- d->decrypted[d->n_decrypted].name = name;
- name = NULL;
-
- d->decrypted[d->n_decrypted].device = cd;
- cd = NULL;
+ d->decrypted[d->n_decrypted].name = TAKE_PTR(name);
+ d->decrypted[d->n_decrypted].device = TAKE_PTR(cd);
d->n_decrypted++;
- m->decrypted_node = node;
- node = NULL;
+ m->decrypted_node = TAKE_PTR(node);
return 0;
}
@@ -997,15 +984,11 @@ static int verity_partition(
if (r < 0)
return r;
- d->decrypted[d->n_decrypted].name = name;
- name = NULL;
-
- d->decrypted[d->n_decrypted].device = cd;
- cd = NULL;
+ d->decrypted[d->n_decrypted].name = TAKE_PTR(name);
+ d->decrypted[d->n_decrypted].device = TAKE_PTR(cd);
d->n_decrypted++;
- m->decrypted_node = node;
- node = NULL;
+ m->decrypted_node = TAKE_PTR(node);
return 0;
}
@@ -1074,8 +1057,7 @@ int dissected_image_decrypt(
}
}
- *ret = d;
- d = NULL;
+ *ret = TAKE_PTR(d);
return 1;
#else
@@ -1233,11 +1215,9 @@ int root_hash_load(const char *image, void **ret, size_t *ret_size) {
if (l < sizeof(sd_id128_t))
return -EINVAL;
- *ret = k;
+ *ret = TAKE_PTR(k);
*ret_size = l;
- k = NULL;
-
return 1;
}
diff --git a/src/shared/dns-domain.c b/src/shared/dns-domain.c
index 89d18431e4..af933cdca5 100644
--- a/src/shared/dns-domain.c
+++ b/src/shared/dns-domain.c
@@ -408,10 +408,9 @@ int dns_name_concat(const char *a, const char *b, char **_ret) {
if (a)
p = a;
- else if (b) {
- p = b;
- b = NULL;
- } else
+ else if (b)
+ p = TAKE_PTR(b);
+ else
goto finish;
for (;;) {
@@ -426,8 +425,7 @@ int dns_name_concat(const char *a, const char *b, char **_ret) {
if (b) {
/* Now continue with the second string, if there is one */
- p = b;
- b = NULL;
+ p = TAKE_PTR(b);
continue;
}
@@ -477,8 +475,7 @@ finish:
}
ret[n] = 0;
- *_ret = ret;
- ret = NULL;
+ *_ret = TAKE_PTR(ret);
}
return 0;
@@ -675,8 +672,8 @@ int dns_name_change_suffix(const char *name, const char *old_suffix, const char
/* Not the same, let's jump back, and try with the next label again */
s = old_suffix;
- n = saved_after;
- saved_after = saved_before = NULL;
+ n = TAKE_PTR(saved_after);
+ saved_before = NULL;
}
}
@@ -1111,20 +1108,14 @@ finish:
if (r < 0)
return r;
- if (_domain) {
- *_domain = domain;
- domain = NULL;
- }
+ if (_domain)
+ *_domain = TAKE_PTR(domain);
- if (_type) {
- *_type = type;
- type = NULL;
- }
+ if (_type)
+ *_type = TAKE_PTR(type);
- if (_name) {
- *_name = name;
- name = NULL;
- }
+ if (_name)
+ *_name = TAKE_PTR(name);
return 0;
}
@@ -1307,8 +1298,8 @@ int dns_name_apply_idna(const char *name, char **ret) {
}
}
- *ret = t;
- t = NULL;
+ *ret = TAKE_PTR(t);
+
return 1; /* *ret has been written */
}
@@ -1365,8 +1356,7 @@ int dns_name_apply_idna(const char *name, char **ret) {
return -ENOMEM;
buf[n] = 0;
- *ret = buf;
- buf = NULL;
+ *ret = TAKE_PTR(buf);
return 1;
#else
diff --git a/src/shared/efivars.c b/src/shared/efivars.c
index d31cf2d860..af9587a1c2 100644
--- a/src/shared/efivars.c
+++ b/src/shared/efivars.c
@@ -427,16 +427,12 @@ int efi_get_boot_option(
}
}
- if (title) {
- *title = s;
- s = NULL;
- }
+ if (title)
+ *title = TAKE_PTR(s);
if (part_uuid)
*part_uuid = p_uuid;
- if (path) {
- *path = p;
- p = NULL;
- }
+ if (path)
+ *path = TAKE_PTR(p);
if (active)
*active = !!(header->attr & LOAD_OPTION_ACTIVE);
@@ -628,8 +624,8 @@ int efi_get_boot_options(uint16_t **options) {
qsort_safe(list, count, sizeof(uint16_t), cmp_uint16);
- *options = list;
- list = NULL;
+ *options = TAKE_PTR(list);
+
return count;
}
diff --git a/src/shared/install.c b/src/shared/install.c
index 477e15a4da..d7f7edad95 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -2312,8 +2312,7 @@ int unit_file_revert(
if (!GREEDY_REALLOC0(todo, n_allocated, n_todo + 2))
return -ENOMEM;
- todo[n_todo++] = dropin;
- dropin = NULL;
+ todo[n_todo++] = TAKE_PTR(dropin);
}
}
}
@@ -2342,8 +2341,7 @@ int unit_file_revert(
if (!GREEDY_REALLOC0(todo, n_allocated, n_todo + 2))
return -ENOMEM;
- todo[n_todo++] = path;
- path = NULL;
+ todo[n_todo++] = TAKE_PTR(path);
}
}
}
diff --git a/src/shared/loop-util.c b/src/shared/loop-util.c
index 0f3defd581..d2c3bb501c 100644
--- a/src/shared/loop-util.c
+++ b/src/shared/loop-util.c
@@ -100,14 +100,11 @@ int loop_device_make(int fd, int open_flags, LoopDevice **ret) {
return -ENOMEM;
*d = (LoopDevice) {
- .fd = loop,
- .node = loopdev,
+ .fd = TAKE_FD(loop),
+ .node = TAKE_PTR(loopdev),
.nr = nr,
};
- loop = -1;
- loopdev = NULL;
-
*ret = d;
return (*ret)->fd;
diff --git a/src/shared/machine-image.c b/src/shared/machine-image.c
index 89fd8c5dba..607f69930d 100644
--- a/src/shared/machine-image.c
+++ b/src/shared/machine-image.c
@@ -159,8 +159,7 @@ static int image_new(
path_kill_slashes(i->path);
- *ret = i;
- i = NULL;
+ *ret = TAKE_PTR(i);
return 0;
}
diff --git a/src/shared/path-lookup.c b/src/shared/path-lookup.c
index a472e80aec..792175a8d8 100644
--- a/src/shared/path-lookup.c
+++ b/src/shared/path-lookup.c
@@ -302,11 +302,10 @@ static int acquire_generator_dirs(
if (!z)
return -ENOMEM;
- *generator = x;
- *generator_early = y;
- *generator_late = z;
+ *generator = TAKE_PTR(x);
+ *generator_early = TAKE_PTR(y);
+ *generator_late = TAKE_PTR(z);
- x = y = z = NULL;
return 0;
}
@@ -381,9 +380,8 @@ static int acquire_config_dirs(UnitFileScope scope, char **persistent, char **ru
if (!a || !b)
return -ENOMEM;
- *persistent = a;
- *runtime = b;
- a = b = NULL;
+ *persistent = TAKE_PTR(a);
+ *runtime = TAKE_PTR(b);
return 0;
}
@@ -647,12 +645,10 @@ int lookup_paths_init(
r = strv_extend_strv(&paths, add, true);
if (r < 0)
return r;
- } else {
+ } else
/* Small optimization: if paths is NULL (and it usually is), we can simply assign 'add' to it,
* and don't have to copy anything */
- paths = add;
- add = NULL;
- }
+ paths = TAKE_PTR(add);
}
r = patch_root_prefix(&persistent_config, root);
@@ -691,27 +687,20 @@ int lookup_paths_init(
p->search_path = strv_uniq(paths);
paths = NULL;
- p->persistent_config = persistent_config;
- p->runtime_config = runtime_config;
- persistent_config = runtime_config = NULL;
-
- p->generator = generator;
- p->generator_early = generator_early;
- p->generator_late = generator_late;
- generator = generator_early = generator_late = NULL;
+ p->persistent_config = TAKE_PTR(persistent_config);
+ p->runtime_config = TAKE_PTR(runtime_config);
- p->transient = transient;
- transient = NULL;
+ p->generator = TAKE_PTR(generator);
+ p->generator_early = TAKE_PTR(generator_early);
+ p->generator_late = TAKE_PTR(generator_late);
- p->persistent_control = persistent_control;
- p->runtime_control = runtime_control;
- persistent_control = runtime_control = NULL;
+ p->transient = TAKE_PTR(transient);
- p->root_dir = root;
- root = NULL;
+ p->persistent_control = TAKE_PTR(persistent_control);
+ p->runtime_control = TAKE_PTR(runtime_control);
- p->temporary_dir = tempdir;
- tempdir = NULL;
+ p->root_dir = TAKE_PTR(root);
+ p->temporary_dir = TAKE_PTR(tempdir);
return 0;
}
diff --git a/src/shared/ptyfwd.c b/src/shared/ptyfwd.c
index 94a4dd513f..d587395c5e 100644
--- a/src/shared/ptyfwd.c
+++ b/src/shared/ptyfwd.c
@@ -495,8 +495,7 @@ int pty_forward_new(
(void) sd_event_source_set_description(f->sigwinch_event_source, "ptyfwd-sigwinch");
- *ret = f;
- f = NULL;
+ *ret = TAKE_PTR(f);
return 0;
}
diff --git a/src/shared/seccomp-util.c b/src/shared/seccomp-util.c
index 13c83097a5..65b14a3c0d 100644
--- a/src/shared/seccomp-util.c
+++ b/src/shared/seccomp-util.c
@@ -1613,8 +1613,7 @@ int parse_syscall_archs(char **l, Set **archs) {
return -ENOMEM;
}
- *archs = _archs;
- _archs = NULL;
+ *archs = TAKE_PTR(_archs);
return 0;
}
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 12fca4ef9a..b4cbe126f6 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -680,8 +680,7 @@ static int get_unit_list(
if (r < 0)
return bus_log_parse_error(r);
- *_reply = reply;
- reply = NULL;
+ *_reply = TAKE_PTR(reply);
return c;
}
@@ -752,16 +751,13 @@ static int get_unit_list_recursive(
}
}
- *_machines = machines;
- machines = NULL;
+ *_machines = TAKE_PTR(machines);
} else
*_machines = NULL;
- *_unit_infos = unit_infos;
- unit_infos = NULL;
+ *_unit_infos = TAKE_PTR(unit_infos);
- *_replies = replies;
- replies = NULL;
+ *_replies = TAKE_PTR(replies);
return c;
}
@@ -1334,10 +1330,8 @@ static int list_timers(int argc, char *argv[], void *userdata) {
.id = u->id,
.next_elapse = m,
.last_trigger = last,
- .triggered = triggered,
+ .triggered = TAKE_PTR(triggered),
};
-
- triggered = NULL; /* avoid cleanup */
}
qsort_safe(timer_infos, c, sizeof(struct timer_info),
@@ -1705,8 +1699,7 @@ static int list_dependencies_get_dependencies(sd_bus *bus, const char *name, cha
info.dep[i] = strv_free(info.dep[i]);
}
- *deps = ret;
- ret = NULL;
+ *deps = TAKE_PTR(ret);
return 0;
}
@@ -2606,14 +2599,12 @@ static int unit_find_paths(
r = 0;
if (!isempty(path)) {
- *fragment_path = path;
- path = NULL;
+ *fragment_path = TAKE_PTR(path);
r = 1;
}
if (dropin_paths && !strv_isempty(dropins)) {
- *dropin_paths = dropins;
- dropins = NULL;
+ *dropin_paths = TAKE_PTR(dropins);
r = 1;
}
not_found:
@@ -3008,8 +2999,7 @@ static int expand_names(sd_bus *bus, char **names, const char* suffix, char ***r
}
}
- *ret = mangled;
- mangled = NULL; /* do not free */
+ *ret = TAKE_PTR(mangled);
return 0;
}
diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c
index f6878a9c01..1b452ca707 100644
--- a/src/sysusers/sysusers.c
+++ b/src/sysusers/sysusers.c
@@ -464,10 +464,9 @@ static int write_temporary_passwd(const char *passwd_path, FILE **tmpfile, char
if (r < 0)
return r;
- *tmpfile = passwd;
- *tmpfile_path = passwd_tmp;
- passwd = NULL;
- passwd_tmp = NULL;
+ *tmpfile = TAKE_PTR(passwd);
+ *tmpfile_path = TAKE_PTR(passwd_tmp);
+
return 0;
}
@@ -564,10 +563,9 @@ static int write_temporary_shadow(const char *shadow_path, FILE **tmpfile, char
if (r < 0)
return r;
- *tmpfile = shadow;
- *tmpfile_path = shadow_tmp;
- shadow = NULL;
- shadow_tmp = NULL;
+ *tmpfile = TAKE_PTR(shadow);
+ *tmpfile_path = TAKE_PTR(shadow_tmp);
+
return 0;
}
@@ -663,10 +661,8 @@ static int write_temporary_group(const char *group_path, FILE **tmpfile, char **
return r;
if (group_changed) {
- *tmpfile = group;
- *tmpfile_path = group_tmp;
- group = NULL;
- group_tmp = NULL;
+ *tmpfile = TAKE_PTR(group);
+ *tmpfile_path = TAKE_PTR(group_tmp);
}
return 0;
}
@@ -737,10 +733,8 @@ static int write_temporary_gshadow(const char * gshadow_path, FILE **tmpfile, ch
return r;
if (group_changed) {
- *tmpfile = gshadow;
- *tmpfile_path = gshadow_tmp;
- gshadow = NULL;
- gshadow_tmp = NULL;
+ *tmpfile = TAKE_PTR(gshadow);
+ *tmpfile_path = TAKE_PTR(gshadow_tmp);
}
return 0;
#else
@@ -1604,8 +1598,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
if (resolved_id) {
if (path_is_absolute(resolved_id)) {
- i->uid_path = resolved_id;
- resolved_id = NULL;
+ i->uid_path = TAKE_PTR(resolved_id);
path_kill_slashes(i->uid_path);
} else {
@@ -1627,14 +1620,9 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
}
}
- i->description = description;
- description = NULL;
-
- i->home = home;
- home = NULL;
-
- i->shell = resolved_shell;
- resolved_shell = NULL;
+ i->description = TAKE_PTR(description);
+ i->home = TAKE_PTR(home);
+ i->shell = TAKE_PTR(resolved_shell);
h = users;
break;
@@ -1662,8 +1650,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
if (resolved_id) {
if (path_is_absolute(resolved_id)) {
- i->gid_path = resolved_id;
- resolved_id = NULL;
+ i->gid_path = TAKE_PTR(resolved_id);
path_kill_slashes(i->gid_path);
} else {
@@ -1683,8 +1670,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
}
i->type = action[0];
- i->name = resolved_name;
- resolved_name = NULL;
+ i->name = TAKE_PTR(resolved_name);
existing = ordered_hashmap_get(h, i->name);
if (existing) {
diff --git a/src/sysv-generator/sysv-generator.c b/src/sysv-generator/sysv-generator.c
index 394a04bb88..5b30baee84 100644
--- a/src/sysv-generator/sysv-generator.c
+++ b/src/sysv-generator/sysv-generator.c
@@ -809,9 +809,8 @@ static int enumerate_sysv(const LookupPaths *lp, Hashmap *all_services) {
return log_oom();
service->sysv_start_priority = -1;
- service->name = name;
- service->path = fpath;
- name = fpath = NULL;
+ service->name = TAKE_PTR(name);
+ service->path = TAKE_PTR(fpath);
r = hashmap_put(all_services, service->name, service);
if (r < 0)
diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index 822835cce9..34ea03892c 100644
--- a/src/timedate/timedated.c
+++ b/src/timedate/timedated.c
@@ -683,8 +683,7 @@ static int connect_bus(Context *c, sd_event *event, sd_bus **_bus) {
if (r < 0)
return log_error_errno(r, "Failed to attach bus to event loop: %m");
- *_bus = bus;
- bus = NULL;
+ *_bus = TAKE_PTR(bus);
return 0;
}
diff --git a/src/timesync/timesyncd-manager.c b/src/timesync/timesyncd-manager.c
index 7743036023..d5eaf64e74 100644
--- a/src/timesync/timesyncd-manager.c
+++ b/src/timesync/timesyncd-manager.c
@@ -488,7 +488,7 @@ static int manager_receive_response(sd_event_source *source, int fd, uint32_t re
.msg_namelen = sizeof(server_addr),
};
struct cmsghdr *cmsg;
- struct timespec *recv_time;
+ struct timespec *recv_time = NULL;
ssize_t len;
double origin, receive, trans, dest;
double delay, offset;
@@ -527,7 +527,6 @@ static int manager_receive_response(sd_event_source *source, int fd, uint32_t re
return 0;
}
- recv_time = NULL;
CMSG_FOREACH(cmsg, &msghdr) {
if (cmsg->cmsg_level != SOL_SOCKET)
continue;
@@ -1154,8 +1153,7 @@ int manager_new(Manager **ret) {
manager_network_read_link_servers(m);
- *ret = m;
- m = NULL;
+ *ret = TAKE_PTR(m);
return 0;
}
diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
index a4368f088d..bd578984df 100644
--- a/src/udev/net/link-config.c
+++ b/src/udev/net/link-config.c
@@ -135,8 +135,7 @@ int link_config_ctx_new(link_config_ctx **ret) {
ctx->enable_name_policy = true;
- *ret = ctx;
- ctx = NULL;
+ *ret = TAKE_PTR(ctx);
return 0;
}
diff --git a/src/udev/udevd.c b/src/udev/udevd.c
index 34976b30e0..254a72556e 100644
--- a/src/udev/udevd.c
+++ b/src/udev/udevd.c
@@ -352,8 +352,7 @@ static void worker_spawn(Manager *manager, struct event *event) {
sigset_t mask;
/* take initial device from queue */
- dev = event->dev;
- event->dev = NULL;
+ dev = TAKE_PTR(event->dev);
unsetenv("NOTIFY_SOCKET");
@@ -1605,8 +1604,7 @@ static int manager_new(Manager **ret, int fd_ctrl, int fd_uevent, const char *cg
if (r < 0)
return log_error_errno(r, "error creating post event source: %m");
- *ret = manager;
- manager = NULL;
+ *ret = TAKE_PTR(manager);
return 0;
}