tree-wide: use TAKE_PTR() and TAKE_FD() macros

This commit is contained in:
Yu Watanabe 2018-04-05 14:26:26 +09:00
parent 3d282fff06
commit 1cc6c93a95
136 changed files with 383 additions and 736 deletions

View File

@ -491,8 +491,7 @@ static int acquire_host_info(sd_bus *bus, struct host_info **hi) {
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to get host information from systemd: %s", bus_error_message(&error, r)); return log_error_errno(r, "Failed to get host information from systemd: %s", bus_error_message(&error, r));
*hi = host; *hi = TAKE_PTR(host);
host = NULL;
return 0; return 0;
} }

View File

@ -42,8 +42,8 @@ int bpf_program_new(uint32_t prog_type, BPFProgram **ret) {
p->prog_type = prog_type; p->prog_type = prog_type;
p->kernel_fd = -1; p->kernel_fd = -1;
*ret = p; *ret = TAKE_PTR(p);
p = NULL;
return 0; return 0;
} }

View File

@ -1841,8 +1841,7 @@ int btrfs_qgroup_find_parents(int fd, uint64_t qgroupid, uint64_t **ret) {
return 0; return 0;
} }
*ret = items; *ret = TAKE_PTR(items);
items = NULL;
return (int) n_items; return (int) n_items;
} }

View File

@ -2448,8 +2448,7 @@ int cg_kernel_controllers(Set **ret) {
return r; return r;
} }
*ret = controllers; *ret = TAKE_PTR(controllers);
controllers = NULL;
return 0; return 0;
} }

View File

@ -111,10 +111,8 @@ int parse_cpu_set_internal(
} }
/* On success, sets *cpu_set and returns ncpus for the system. */ /* On success, sets *cpu_set and returns ncpus for the system. */
if (c) { if (c)
*cpu_set = c; *cpu_set = TAKE_PTR(c);
c = NULL;
}
return (int) ncpus; return (int) ncpus;
} }

View File

@ -1606,8 +1606,7 @@ int read_line(FILE *f, size_t limit, char **ret) {
if (ret) { if (ret) {
buffer[n] = 0; buffer[n] = 0;
*ret = buffer; *ret = TAKE_PTR(buffer);
buffer = NULL;
} }
return (int) count; return (int) count;

View File

@ -125,8 +125,7 @@ int unhexmem(const char *p, size_t l, void **mem, size_t *len) {
*z = 0; *z = 0;
*mem = r; *mem = TAKE_PTR(r);
r = NULL;
*len = (l + 1) / 2; *len = (l + 1) / 2;
return 0; return 0;
@ -482,8 +481,7 @@ int unbase32hexmem(const char *p, size_t l, bool padding, void **mem, size_t *_l
*z = 0; *z = 0;
*mem = r; *mem = TAKE_PTR(r);
r = NULL;
*_len = len; *_len = len;
return 0; return 0;
@ -751,8 +749,7 @@ int unbase64mem(const char *p, size_t l, void **ret, size_t *ret_size) {
if (ret_size) if (ret_size)
*ret_size = (size_t) (z - buf); *ret_size = (size_t) (z - buf);
*ret = buf; *ret = TAKE_PTR(buf);
buf = NULL;
return 0; return 0;
} }

View File

@ -216,8 +216,7 @@ int khash_dup(khash *h, khash **ret) {
if (copy->fd < 0) if (copy->fd < 0)
return -errno; return -errno;
*ret = copy; *ret = TAKE_PTR(copy);
copy = NULL;
return 0; return 0;
} }

View File

@ -196,8 +196,7 @@ int get_locales(char ***ret) {
strv_sort(l); strv_sort(l);
*ret = l; *ret = TAKE_PTR(l);
l = NULL;
return 0; return 0;
} }

View File

@ -18,6 +18,7 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>. along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/ ***/
#include "alloc-util.h"
#include "set.h" #include "set.h"
int set_make(Set **ret, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS, void *add, ...) { 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); va_end(ap);
} }
*ret = s; *ret = TAKE_PTR(s);
s = NULL;
return 0; return 0;
} }

View File

@ -1017,8 +1017,7 @@ int getpeergroups(int fd, gid_t **ret) {
if ((socklen_t) (int) n != n) if ((socklen_t) (int) n != n)
return -E2BIG; return -E2BIG;
*ret = d; *ret = TAKE_PTR(d);
d = NULL;
return (int) n; return (int) n;
} }

View File

@ -1283,8 +1283,7 @@ int get_timezones(char ***ret) {
} else if (errno != ENOENT) } else if (errno != ENOENT)
return -errno; return -errno;
*ret = zones; *ret = TAKE_PTR(zones);
zones = NULL;
return 0; return 0;
} }

View File

@ -137,8 +137,7 @@ static int acquire_bus(bool set_monitor, sd_bus **ret) {
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to connect to bus: %m"); return log_error_errno(r, "Failed to connect to bus: %m");
*ret = bus; *ret = TAKE_PTR(bus);
bus = NULL;
return 0; return 0;
} }

View File

@ -311,8 +311,7 @@ static int bpf_firewall_compile_bpf(
return r; return r;
} while (false); } while (false);
*ret = p; *ret = TAKE_PTR(p);
p = NULL;
return 0; return 0;
} }

View File

@ -290,8 +290,7 @@ static int bus_timer_set_transient_property(
return -ENOMEM; return -ENOMEM;
v->base = b; v->base = b;
v->calendar_spec = c; v->calendar_spec = TAKE_PTR(c);
c = NULL;
LIST_PREPEND(value, t->values, v); LIST_PREPEND(value, t->values, v);
} }
@ -377,8 +376,7 @@ static int bus_timer_set_transient_property(
return -ENOMEM; return -ENOMEM;
v->base = TIMER_CALENDAR; v->base = TIMER_CALENDAR;
v->calendar_spec = c; v->calendar_spec = TAKE_PTR(c);
c = NULL;
LIST_PREPEND(value, t->values, v); LIST_PREPEND(value, t->values, v);
} }

View File

@ -914,8 +914,7 @@ int bus_init_api(Manager *m) {
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to set up API bus: %m"); return log_error_errno(r, "Failed to set up API bus: %m");
m->api_bus = bus; m->api_bus = TAKE_PTR(bus);
bus = NULL;
r = manager_enqueue_sync_bus_names(m); r = manager_enqueue_sync_bus_names(m);
if (r < 0) if (r < 0)
@ -976,8 +975,7 @@ int bus_init_system(Manager *m) {
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to set up system bus: %m"); return log_error_errno(r, "Failed to set up system bus: %m");
m->system_bus = bus; m->system_bus = TAKE_PTR(bus);
bus = NULL;
return 0; return 0;
} }

View File

@ -1757,9 +1757,8 @@ static int build_pass_environment(const ExecContext *c, char ***ret) {
if (!GREEDY_REALLOC(pass_env, n_bufsize, n_env + 2)) if (!GREEDY_REALLOC(pass_env, n_bufsize, n_env + 2))
return -ENOMEM; return -ENOMEM;
pass_env[n_env++] = x; pass_env[n_env++] = TAKE_PTR(x);
pass_env[n_env] = NULL; pass_env[n_env] = NULL;
x = NULL;
} }
*ret = TAKE_PTR(pass_env); *ret = TAKE_PTR(pass_env);

View File

@ -1439,8 +1439,7 @@ int job_get_before(Job *j, Job*** ret) {
n = sort_job_list(list, n); n = sort_job_list(list, n);
*ret = list; *ret = TAKE_PTR(list);
list = NULL;
return (int) n; return (int) n;
} }
@ -1489,8 +1488,7 @@ int job_get_after(Job *j, Job*** ret) {
n = sort_job_list(list, n); n = sort_job_list(list, n);
*ret = list; *ret = TAKE_PTR(list);
list = NULL;
return (int) n; return (int) n;
} }

View File

@ -146,10 +146,9 @@ int unit_load_dropin(Unit *u) {
if (r <= 0) if (r <= 0)
return 0; return 0;
if (!u->dropin_paths) { if (!u->dropin_paths)
u->dropin_paths = l; u->dropin_paths = TAKE_PTR(l);
l = NULL; else {
} else {
r = strv_extend_strv(&u->dropin_paths, l, true); r = strv_extend_strv(&u->dropin_paths, l, true);
if (r < 0) if (r < 0)
return log_oom(); return log_oom();

View File

@ -731,9 +731,9 @@ int config_parse_exec(
if (!GREEDY_REALLOC(n, nbufsize, nlen + 2)) if (!GREEDY_REALLOC(n, nbufsize, nlen + 2))
return log_oom(); return log_oom();
n[nlen++] = resolved;
n[nlen++] = TAKE_PTR(resolved);
n[nlen] = NULL; n[nlen] = NULL;
resolved = NULL;
} }
if (!n || !n[0]) { if (!n || !n[0]) {
@ -747,15 +747,13 @@ int config_parse_exec(
if (!nce) if (!nce)
return log_oom(); return log_oom();
nce->argv = n; nce->argv = TAKE_PTR(n);
nce->path = path; nce->path = TAKE_PTR(path);
nce->flags = flags; nce->flags = flags;
exec_command_append_list(e, nce); exec_command_append_list(e, nce);
/* Do not _cleanup_free_ these. */ /* Do not _cleanup_free_ these. */
n = NULL;
path = NULL;
nce = NULL; nce = NULL;
rvalue = p; rvalue = p;
@ -2397,9 +2395,8 @@ int config_parse_pass_environ(
if (!GREEDY_REALLOC(n, nbufsize, nlen + 2)) if (!GREEDY_REALLOC(n, nbufsize, nlen + 2))
return log_oom(); return log_oom();
n[nlen++] = k; n[nlen++] = TAKE_PTR(k);
n[nlen] = NULL; n[nlen] = NULL;
k = NULL;
} }
if (n) { if (n) {
@ -2474,9 +2471,8 @@ int config_parse_unset_environ(
if (!GREEDY_REALLOC(n, nbufsize, nlen + 2)) if (!GREEDY_REALLOC(n, nbufsize, nlen + 2))
return log_oom(); return log_oom();
n[nlen++] = k; n[nlen++] = TAKE_PTR(k);
n[nlen] = NULL; n[nlen] = NULL;
k = NULL;
} }
if (n) { if (n) {
@ -4762,9 +4758,7 @@ static int load_from_path(Unit *u, const char *path) {
return r; return r;
} }
free(u->fragment_path); free_and_replace(u->fragment_path, filename);
u->fragment_path = filename;
filename = NULL;
if (u->source_path) { if (u->source_path) {
if (stat(u->source_path, &st) >= 0) if (stat(u->source_path, &st) >= 0)

View File

@ -1131,11 +1131,8 @@ static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool switching
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to disable O_CLOEXEC for serialization fds: %m"); return log_error_errno(r, "Failed to disable O_CLOEXEC for serialization fds: %m");
*_f = f; *_f = TAKE_PTR(f);
*_fds = fds; *_fds = TAKE_PTR(fds);
f = NULL;
fds = NULL;
return 0; return 0;
} }

View File

@ -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, /* 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. */ * since they might have gotten serialized across the reexec. */
*_m = m; *_m = TAKE_PTR(m);
m = NULL;
return 0; return 0;
} }
@ -1894,8 +1894,7 @@ int manager_get_dump_string(Manager *m, char **ret) {
f = safe_fclose(f); f = safe_fclose(f);
*ret = dump; *ret = TAKE_PTR(dump);
dump = NULL;
return 0; return 0;
} }

View File

@ -1395,14 +1395,13 @@ int bind_mount_add(BindMount **b, unsigned *n, const BindMount *item) {
*b = c; *b = c;
c[(*n) ++] = (BindMount) { c[(*n) ++] = (BindMount) {
.source = s, .source = TAKE_PTR(s),
.destination = d, .destination = TAKE_PTR(d),
.read_only = item->read_only, .read_only = item->read_only,
.recursive = item->recursive, .recursive = item->recursive,
.ignore_enoent = item->ignore_enoent, .ignore_enoent = item->ignore_enoent,
}; };
s = d = NULL;
return 0; return 0;
} }
@ -1449,11 +1448,10 @@ int temporary_filesystem_add(
*t = c; *t = c;
c[(*n) ++] = (TemporaryFileSystem) { c[(*n) ++] = (TemporaryFileSystem) {
.path = p, .path = TAKE_PTR(p),
.options = o, .options = TAKE_PTR(o),
}; };
p = o = NULL;
return 0; return 0;
} }
@ -1491,8 +1489,7 @@ static int setup_one_tmp_dir(const char *id, const char *prefix, char **path) {
return -errno; return -errno;
} }
*path = x; *path = TAKE_PTR(x);
x = NULL;
return 0; return 0;
} }

View File

@ -1250,10 +1250,8 @@ static int service_collect_fds(Service *s,
continue; continue;
if (!rfds) { if (!rfds) {
rfds = cfds; rfds = TAKE_PTR(cfds);
rn_socket_fds = cn_fds; rn_socket_fds = cn_fds;
cfds = NULL;
} else { } else {
int *t; int *t;
@ -1305,14 +1303,11 @@ static int service_collect_fds(Service *s,
rfd_names[n_fds] = NULL; rfd_names[n_fds] = NULL;
} }
*fds = rfds; *fds = TAKE_PTR(rfds);
*fd_names = rfd_names; *fd_names = TAKE_PTR(rfd_names);
*n_socket_fds = rn_socket_fds; *n_socket_fds = rn_socket_fds;
*n_storage_fds = rn_storage_fds; *n_storage_fds = rn_storage_fds;
rfds = NULL;
rfd_names = NULL;
return 0; return 0;
} }

View File

@ -629,8 +629,7 @@ int socket_acquire_peer(Socket *s, int fd, SocketPeer **p) {
remote->socket = s; remote->socket = s;
*p = remote; *p = TAKE_PTR(remote);
remote = NULL;
return 1; 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. */ cfd = -1; /* We passed ownership of the fd to the service now. Forget it here. */
s->n_connections++; s->n_connections++;
service->peer = p; /* Pass ownership of the peer reference */ service->peer = TAKE_PTR(p); /* Pass ownership of the peer reference */
p = NULL;
r = manager_add_job(UNIT(s)->manager, JOB_START, UNIT(service), JOB_REPLACE, &error, NULL); r = manager_add_job(UNIT(s)->manager, JOB_START, UNIT(service), JOB_REPLACE, &error, NULL);
if (r < 0) { if (r < 0) {

View File

@ -139,8 +139,8 @@ int unit_new_for_name(Manager *m, size_t size, const char *name, Unit **ret) {
if (r < 0) if (r < 0)
return r; return r;
*ret = u; *ret = TAKE_PTR(u);
u = NULL;
return r; return r;
} }
@ -266,13 +266,11 @@ int unit_add_name(Unit *u, const char *text) {
if (u->type == _UNIT_TYPE_INVALID) { if (u->type == _UNIT_TYPE_INVALID) {
u->type = t; u->type = t;
u->id = s; u->id = s;
u->instance = i; u->instance = TAKE_PTR(i);
LIST_PREPEND(units_by_type, u->manager->units_by_type[t], u); LIST_PREPEND(units_by_type, u->manager->units_by_type[t], u);
unit_init(u); unit_init(u);
i = NULL;
} }
s = NULL; s = NULL;

View File

@ -227,8 +227,7 @@ int coredump_vacuum(int exclude_fd, uint64_t keep_free, uint64_t max_use) {
if (r < 0) if (r < 0)
return log_oom(); return log_oom();
c = n; c = TAKE_PTR(n);
n = NULL;
} }
c->n_files++; c->n_files++;

View File

@ -432,14 +432,11 @@ static int save_external_coredump(
if (tmp) if (tmp)
unlink_noerrno(tmp); unlink_noerrno(tmp);
*ret_filename = fn_compressed; /* compressed */ *ret_filename = TAKE_PTR(fn_compressed); /* compressed */
*ret_node_fd = fd_compressed; /* compressed */ *ret_node_fd = TAKE_FD(fd_compressed); /* compressed */
*ret_data_fd = fd; /* uncompressed */ *ret_data_fd = TAKE_FD(fd); /* uncompressed */
*ret_size = (uint64_t) st.st_size; /* uncompressed */ *ret_size = (uint64_t) st.st_size; /* uncompressed */
fn_compressed = NULL;
fd = fd_compressed = -1;
return 0; return 0;
fail_compressed: fail_compressed:
@ -454,14 +451,11 @@ uncompressed:
if (r < 0) if (r < 0)
goto fail; goto fail;
*ret_filename = fn; *ret_filename = TAKE_PTR(fn);
*ret_data_fd = fd; *ret_data_fd = TAKE_FD(fd);
*ret_node_fd = -1; *ret_node_fd = -1;
*ret_size = (uint64_t) st.st_size; *ret_size = (uint64_t) st.st_size;
fn = NULL;
fd = -1;
return 0; return 0;
fail: fail:
@ -497,11 +491,9 @@ static int allocate_journal_field(int fd, size_t size, char **ret, size_t *ret_s
return -EIO; return -EIO;
} }
*ret = field; *ret = TAKE_PTR(field);
*ret_size = size + 9; *ret_size = size + 9;
field = NULL;
return 0; return 0;
} }

View File

@ -146,8 +146,7 @@ static int acquire_journal(sd_journal **ret, char **matches) {
log_debug("Journal filter: %s", filter); log_debug("Journal filter: %s", filter);
} }
*ret = j; *ret = TAKE_PTR(j);
j = NULL;
return 0; return 0;
} }

View File

@ -688,8 +688,7 @@ static int connect_bus(Context *c, sd_event *event, sd_bus **_bus) {
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to attach bus to event loop: %m"); return log_error_errno(r, "Failed to attach bus to event loop: %m");
*_bus = bus; *_bus = TAKE_PTR(bus);
bus = NULL;
return 0; return 0;
} }

View File

@ -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) if (curl_multi_setopt(g->curl, CURLMOPT_TIMERFUNCTION, curl_glue_timer_callback) != CURLM_OK)
return -EINVAL; return -EINVAL;
*glue = g; *glue = TAKE_PTR(g);
g = NULL;
return 0; return 0;
} }

View File

@ -122,8 +122,7 @@ int raw_export_new(
return r; return r;
} }
*ret = e; *ret = TAKE_PTR(e);
e = NULL;
return 0; return 0;
} }

View File

@ -126,8 +126,7 @@ int tar_export_new(
return r; return r;
} }
*ret = e; *ret = TAKE_PTR(e);
e = NULL;
return 0; return 0;
} }

View File

@ -141,8 +141,7 @@ int raw_import_new(
return r; return r;
} }
*ret = i; *ret = TAKE_PTR(i);
i = NULL;
return 0; return 0;
} }

View File

@ -148,8 +148,7 @@ int tar_import_new(
return r; return r;
} }
*ret = i; *ret = TAKE_PTR(i);
i = NULL;
return 0; return 0;
} }

View File

@ -187,8 +187,7 @@ static int transfer_new(Manager *m, Transfer **ret) {
t->manager = m; t->manager = m;
t->id = id; t->id = id;
*ret = t; *ret = TAKE_PTR(t);
t = NULL;
return 0; return 0;
} }
@ -639,8 +638,7 @@ static int manager_new(Manager **ret) {
if (r < 0) if (r < 0)
return r; return r;
*ret = m; *ret = TAKE_PTR(m);
m = NULL;
return 0; return 0;
} }

View File

@ -258,8 +258,7 @@ int pull_make_auxiliary_job(
job->on_finished = on_finished; job->on_finished = on_finished;
job->compressed_max = job->uncompressed_max = 1ULL * 1024ULL * 1024ULL; job->compressed_max = job->uncompressed_max = 1ULL * 1024ULL * 1024ULL;
*ret = job; *ret = TAKE_PTR(job);
job = NULL;
return 0; return 0;
} }

View File

@ -581,8 +581,7 @@ int pull_job_new(PullJob **ret, const char *url, CurlGlue *glue, void *userdata)
if (!j->url) if (!j->url)
return -ENOMEM; return -ENOMEM;
*ret = j; *ret = TAKE_PTR(j);
j = NULL;
return 0; return 0;
} }

View File

@ -166,8 +166,7 @@ int raw_pull_new(
i->glue->on_finished = pull_job_curl_on_finished; i->glue->on_finished = pull_job_curl_on_finished;
i->glue->userdata = i; i->glue->userdata = i;
*ret = i; *ret = TAKE_PTR(i);
i = NULL;
return 0; return 0;
} }

View File

@ -159,8 +159,7 @@ int tar_pull_new(
i->glue->on_finished = pull_job_curl_on_finished; i->glue->on_finished = pull_job_curl_on_finished;
i->glue->userdata = i; i->glue->userdata = i;
*ret = i; *ret = TAKE_PTR(i);
i = NULL;
return 0; return 0;
} }

View File

@ -259,8 +259,8 @@ static int get_writer(RemoteServer *s, const char *host,
return r; return r;
} }
*writer = w; *writer = TAKE_PTR(w);
w = NULL;
return 0; return 0;
} }

View File

@ -314,10 +314,8 @@ int check_permissions(struct MHD_Connection *connection, int *code, char **hostn
log_debug("Connection from %s", buf); log_debug("Connection from %s", buf);
if (hostname) { if (hostname)
*hostname = buf; *hostname = TAKE_PTR(buf);
buf = NULL;
}
r = verify_cert_authorized(session); r = verify_cert_authorized(session);
if (r < 0) { if (r < 0) {

View File

@ -1939,8 +1939,7 @@ int journal_file_enable_post_change_timer(JournalFile *f, sd_event *e, usec_t t)
if (r < 0) if (r < 0)
return r; return r;
f->post_change_timer = timer; f->post_change_timer = TAKE_PTR(timer);
timer = NULL;
f->post_change_timer_period = t; f->post_change_timer_period = t;
return r; return r;

View File

@ -299,7 +299,7 @@ int journal_directory_vacuum(
goto finish; goto finish;
} }
list[n_list].filename = p; list[n_list].filename = TAKE_PTR(p);
list[n_list].usage = size; list[n_list].usage = size;
list[n_list].seqnum = seqnum; list[n_list].seqnum = seqnum;
list[n_list].realtime = realtime; list[n_list].realtime = realtime;
@ -307,7 +307,6 @@ int journal_directory_vacuum(
list[n_list].have_seqnum = have_seqnum; list[n_list].have_seqnum = have_seqnum;
n_list++; n_list++;
p = NULL;
sum += size; sum += size;
} }

View File

@ -921,10 +921,9 @@ static int parse_argv(int argc, char *argv[]) {
if (!v) if (!v)
return log_oom(); return log_oom();
if (!arg_output_fields) { if (!arg_output_fields)
arg_output_fields = v; arg_output_fields = TAKE_PTR(v);
v = NULL; else {
} else {
r = strv_extend_strv(&arg_output_fields, v, true); r = strv_extend_strv(&arg_output_fields, v, true);
if (r < 0) if (r < 0)
return log_oom(); return log_oom();
@ -1229,8 +1228,7 @@ static int discover_next_boot(sd_journal *j,
if (r < 0) if (r < 0)
return r; return r;
*ret = next_boot; *ret = TAKE_PTR(next_boot);
next_boot = NULL;
return 0; return 0;
} }
@ -1342,8 +1340,7 @@ static int get_boots(
} }
} }
LIST_INSERT_AFTER(boot_list, head, tail, current); LIST_INSERT_AFTER(boot_list, head, tail, current);
tail = current; tail = TAKE_PTR(current);
current = NULL;
count++; count++;
} }
} }
@ -1508,8 +1505,8 @@ static int get_possible_units(
} }
} }
*units = found; *units = TAKE_PTR(found);
found = NULL;
return 0; return 0;
} }

View File

@ -439,14 +439,11 @@ static int client_context_read_extra_fields(
free(c->extra_fields_iovec); free(c->extra_fields_iovec);
free(c->extra_fields_data); 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_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); c->extra_fields_mtime = timespec_load_nsec(&st.st_mtim);
iovec = NULL;
data = NULL;
return 0; return 0;
} }

View File

@ -674,8 +674,7 @@ _public_ int sd_lldp_neighbor_from_raw(sd_lldp_neighbor **ret, const void *raw,
if (r < 0) if (r < 0)
return r; return r;
*ret = n; *ret = TAKE_PTR(n);
n = NULL;
return r; return r;
} }

View File

@ -82,8 +82,7 @@ _public_ int sd_ndisc_router_from_raw(sd_ndisc_router **ret, const void *raw, si
if (r < 0) if (r < 0)
return r; return r;
*ret = rt; *ret = TAKE_PTR(rt);
rt = NULL;
return r; return r;
} }
@ -765,8 +764,7 @@ _public_ int sd_ndisc_router_dnssl_get_domains(sd_ndisc_router *rt, char ***ret)
return 0; return 0;
} }
*ret = l; *ret = TAKE_PTR(l);
l = NULL;
return k; return k;
} }

View File

@ -682,8 +682,7 @@ static int client_message_init(
*_optlen = optlen; *_optlen = optlen;
*_optoffset = optoffset; *_optoffset = optoffset;
*ret = packet; *ret = TAKE_PTR(packet);
packet = NULL;
return 0; return 0;
} }
@ -1288,8 +1287,7 @@ static int client_handle_offer(sd_dhcp_client *client, DHCPMessage *offer, size_
} }
sd_dhcp_lease_unref(client->lease); sd_dhcp_lease_unref(client->lease);
client->lease = lease; client->lease = TAKE_PTR(lease);
lease = NULL;
log_dhcp_client(client, "OFFER"); 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 = sd_dhcp_lease_unref(client->lease);
} }
client->lease = lease; client->lease = TAKE_PTR(lease);
lease = NULL;
log_dhcp_client(client, "ACK"); log_dhcp_client(client, "ACK");
@ -1966,8 +1963,7 @@ int sd_dhcp_client_new(sd_dhcp_client **ret, int anonymize) {
if (!client->req_opts) if (!client->req_opts)
return -ENOMEM; return -ENOMEM;
*ret = client; *ret = TAKE_PTR(client);
client = NULL;
return 0; return 0;
} }

View File

@ -1235,8 +1235,7 @@ int dhcp_lease_load(sd_dhcp_lease **ret, const char *lease_file) {
return r; return r;
} }
*ret = lease; *ret = TAKE_PTR(lease);
lease = NULL;
return 0; return 0;
} }

View File

@ -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->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); server->max_lease_time = DIV_ROUND_UP(DHCP_MAX_LEASE_TIME_USEC, USEC_PER_SEC);
*ret = server; *ret = TAKE_PTR(server);
server = NULL;
return 0; 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); memcpy(&packet->dhcp.chaddr, &req->message->chaddr, ETH_ALEN);
*_optoffset = optoffset; *_optoffset = optoffset;
*ret = packet; *ret = TAKE_PTR(packet);
packet = NULL;
return 0; return 0;
} }

View File

@ -1466,8 +1466,7 @@ int sd_dhcp6_client_new(sd_dhcp6_client **ret) {
for (t = 0; t < client->req_opts_len; t++) for (t = 0; t < client->req_opts_len; t++)
client->req_opts[t] = htobe16(default_req_opts[t]); client->req_opts[t] = htobe16(default_req_opts[t]);
*ret = client; *ret = TAKE_PTR(client);
client = NULL;
return 0; return 0;
} }

View File

@ -153,8 +153,7 @@ int sd_ipv4acd_new(sd_ipv4acd **ret) {
acd->ifindex = -1; acd->ifindex = -1;
acd->fd = -1; acd->fd = -1;
*ret = acd; *ret = TAKE_PTR(acd);
acd = NULL;
return 0; 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"); (void) sd_event_source_set_description(timer, "ipv4acd-timer");
sd_event_source_unref(acd->timer_event_source); sd_event_source_unref(acd->timer_event_source);
acd->timer_event_source = timer; acd->timer_event_source = TAKE_PTR(timer);
timer = NULL;
return 0; return 0;
} }

View File

@ -115,8 +115,7 @@ int sd_ipv4ll_new(sd_ipv4ll **ret) {
if (r < 0) if (r < 0)
return r; return r;
*ret = ll; *ret = TAKE_PTR(ll);
ll = NULL;
return 0; return 0;
} }

View File

@ -402,8 +402,7 @@ _public_ int sd_lldp_new(sd_lldp **ret) {
if (r < 0) if (r < 0)
return r; return r;
*ret = lldp; *ret = TAKE_PTR(lldp);
lldp = NULL;
return 0; return 0;
} }

View File

@ -166,8 +166,7 @@ _public_ int sd_ndisc_new(sd_ndisc **ret) {
nd->n_ref = 1; nd->n_ref = 1;
nd->fd = -1; nd->fd = -1;
*ret = nd; *ret = TAKE_PTR(nd);
nd = NULL;
return 0; return 0;
} }

View File

@ -51,8 +51,7 @@ _public_ int sd_radv_new(sd_radv **ret) {
LIST_HEAD_INIT(ra->prefixes); LIST_HEAD_INIT(ra->prefixes);
*ret = ra; *ret = TAKE_PTR(ra);
ra = NULL;
return 0; 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)); memcpy(opt_rdnss + 1, dns, n_dns * sizeof(struct in6_addr));
free(ra->rdnss); free_and_replace(ra->rdnss, opt_rdnss);
ra->rdnss = opt_rdnss;
opt_rdnss = NULL;
ra->n_rdnss = n_dns; ra->n_rdnss = n_dns;
@ -724,9 +721,7 @@ _public_ int sd_radv_set_dnssl(sd_radv *ra, uint32_t lifetime,
len -= r; len -= r;
} }
free(ra->dnssl); free_and_replace(ra->dnssl, opt_dnssl);
ra->dnssl = opt_dnssl;
opt_dnssl = NULL;
return 0; return 0;
} }
@ -755,8 +750,7 @@ _public_ int sd_radv_prefix_new(sd_radv_prefix **ret) {
LIST_INIT(prefix, p); LIST_INIT(prefix, p);
*ret = p; *ret = TAKE_PTR(p);
p = NULL;
return 0; return 0;
} }

View File

@ -431,14 +431,11 @@ _public_ int sd_bus_list_names(sd_bus *bus, char ***acquired, char ***activatabl
if (r < 0) if (r < 0)
return r; return r;
*activatable = y; *activatable = TAKE_PTR(y);
y = NULL;
} }
if (acquired) { if (acquired)
*acquired = x; *acquired = TAKE_PTR(x);
x = NULL;
}
return 0; return 0;
} }
@ -734,10 +731,8 @@ _public_ int sd_bus_get_name_creds(
return r; return r;
} }
if (creds) { if (creds)
*creds = c; *creds = TAKE_PTR(c);
c = NULL;
}
return 0; 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) if (r < 0)
return r; return r;
*ret = c; *ret = TAKE_PTR(c);
c = NULL;
return 0; return 0;
} }

View File

@ -1344,7 +1344,7 @@ int bus_creds_extend_by_pid(sd_bus_creds *c, uint64_t mask, sd_bus_creds **ret)
if (r < 0) if (r < 0)
return r; return r;
*ret = n; *ret = TAKE_PTR(n);
n = NULL;
return 0; return 0;
} }

View File

@ -903,11 +903,10 @@ int bus_match_parse(
} }
components[n_components].type = t; 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; components[n_components].value_u8 = u;
n_components++; n_components++;
value = NULL;
if (q[quoted] == 0) if (q[quoted] == 0)
break; break;

View File

@ -513,8 +513,7 @@ int bus_message_from_header(
} }
m->bus = sd_bus_ref(bus); m->bus = sd_bus_ref(bus);
*ret = m; *ret = TAKE_PTR(m);
m = NULL;
return 0; return 0;
} }
@ -5869,8 +5868,7 @@ int bus_message_remarshal(sd_bus *bus, sd_bus_message **m) {
return r; return r;
sd_bus_message_unref(*m); sd_bus_message_unref(*m);
*m = n; *m = TAKE_PTR(n);
n = NULL;
return 0; return 0;
} }

View File

@ -524,8 +524,7 @@ static int synthesize_connected_signal(sd_bus *bus) {
/* Insert at the very front */ /* Insert at the very front */
memmove(bus->rqueue + 1, bus->rqueue, sizeof(sd_bus_message*) * bus->rqueue_size); memmove(bus->rqueue + 1, bus->rqueue, sizeof(sd_bus_message*) * bus->rqueue_size);
bus->rqueue[0] = m; bus->rqueue[0] = TAKE_PTR(m);
m = NULL;
bus->rqueue_size++; bus->rqueue_size++;
return 0; return 0;
@ -2775,8 +2774,8 @@ static int process_running(sd_bus *bus, bool hint_priority, int64_t priority, sd
if (r < 0) if (r < 0)
return r; return r;
*ret = m; *ret = TAKE_PTR(m);
m = NULL;
return 1; return 1;
} }
@ -2935,10 +2934,8 @@ static int process_closing(sd_bus *bus, sd_bus_message **ret) {
bus->exit_triggered = true; bus->exit_triggered = true;
(void) bus_exit_now(bus); (void) bus_exit_now(bus);
if (ret) { if (ret)
*ret = m; *ret = TAKE_PTR(m);
m = NULL;
}
r = 1; r = 1;

View File

@ -71,8 +71,7 @@ _public_ int sd_device_enumerator_new(sd_device_enumerator **ret) {
enumerator->n_ref = 1; enumerator->n_ref = 1;
enumerator->type = _DEVICE_ENUMERATION_TYPE_INVALID; enumerator->type = _DEVICE_ENUMERATION_TYPE_INVALID;
*ret = enumerator; *ret = TAKE_PTR(enumerator);
enumerator = NULL;
return 0; return 0;
} }

View File

@ -586,8 +586,7 @@ int device_new_from_strv(sd_device **ret, char **strv) {
if (r < 0) if (r < 0)
return r; return r;
*ret = device; *ret = TAKE_PTR(device);
device = NULL;
return 0; return 0;
} }
@ -635,8 +634,7 @@ int device_new_from_nulstr(sd_device **ret, uint8_t *nulstr, size_t len) {
if (r < 0) if (r < 0)
return r; return r;
*ret = device; *ret = TAKE_PTR(device);
device = NULL;
return 0; return 0;
} }
@ -812,8 +810,7 @@ int device_shallow_clone(sd_device *old_device, sd_device **new_device) {
ret->devnum = old_device->devnum; ret->devnum = old_device->devnum;
*new_device = ret; *new_device = TAKE_PTR(ret);
ret = NULL;
return 0; return 0;
} }
@ -835,8 +832,7 @@ int device_clone_with_db(sd_device *old_device, sd_device **new_device) {
ret->sealed = true; ret->sealed = true;
*new_device = ret; *new_device = TAKE_PTR(ret);
ret = NULL;
return 0; return 0;
} }
@ -861,8 +857,7 @@ int device_new_from_synthetic_event(sd_device **new_device, const char *syspath,
if (r < 0) if (r < 0)
return r; return r;
*new_device = ret; *new_device = TAKE_PTR(ret);
ret = NULL;
return 0; return 0;
} }

View File

@ -46,7 +46,7 @@
#include "util.h" #include "util.h"
int device_new_aux(sd_device **ret) { int device_new_aux(sd_device **ret) {
_cleanup_(sd_device_unrefp) sd_device *device = NULL; sd_device *device = NULL;
assert(ret); assert(ret);
@ -58,7 +58,6 @@ int device_new_aux(sd_device **ret) {
device->watch_handle = -1; device->watch_handle = -1;
*ret = device; *ret = device;
device = NULL;
return 0; return 0;
} }
@ -247,8 +246,7 @@ _public_ int sd_device_new_from_syspath(sd_device **ret, const char *syspath) {
if (r < 0) if (r < 0)
return r; return r;
*ret = device; *ret = TAKE_PTR(device);
device = NULL;
return 0; 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) if (ifr.ifr_ifindex != ifindex)
return -ENODEV; return -ENODEV;
*ret = device; *ret = TAKE_PTR(device);
device = NULL;
return 0; return 0;
} }
@ -1833,8 +1830,7 @@ _public_ int sd_device_get_sysattr_value(sd_device *device, const char *sysattr,
if (r < 0) if (r < 0)
return r; return r;
*_value = value; *_value = TAKE_PTR(value);
value = NULL;
return 0; return 0;
} }

View File

@ -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("strings %8"PRIu64" bytes", le64toh(hwdb->head->strings_len));
log_debug("nodes %8"PRIu64" bytes", le64toh(hwdb->head->nodes_len)); log_debug("nodes %8"PRIu64" bytes", le64toh(hwdb->head->nodes_len));
*ret = hwdb; *ret = TAKE_PTR(hwdb);
hwdb = NULL;
return 0; return 0;
} }

View File

@ -741,15 +741,11 @@ _public_ int sd_seat_get_sessions(const char *seat, char ***sessions, uid_t **ui
r = strv_length(a); r = strv_length(a);
if (sessions) { if (sessions)
*sessions = a; *sessions = TAKE_PTR(a);
a = NULL;
}
if (uids) { if (uids)
*uids = b; *uids = TAKE_PTR(b);
b = NULL;
}
if (n_uids) if (n_uids)
*n_uids = n; *n_uids = n;
@ -864,10 +860,8 @@ _public_ int sd_get_uids(uid_t **users) {
r++; r++;
} }
if (users) { if (users)
*users = l; *users = TAKE_PTR(l);
l = NULL;
}
return r; return r;
} }

View File

@ -58,8 +58,7 @@ static int genl_message_new(sd_netlink *nl, sd_genl_family family, uint16_t nlms
genl->cmd = cmd; genl->cmd = cmd;
genl->version = genl_families[family].version; genl->version = genl_families[family].version;
*ret = m; *ret = TAKE_PTR(m);
m = NULL;
return 0; return 0;
} }

View File

@ -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); qsort_safe(list, n_list, sizeof(struct local_address), address_compare);
*ret = list; *ret = TAKE_PTR(list);
list = NULL;
return (int) n_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) if (n_list > 0)
qsort(list, n_list, sizeof(struct local_address), address_compare); qsort(list, n_list, sizeof(struct local_address), address_compare);
*ret = list; *ret = TAKE_PTR(list);
list = NULL;
return (int) n_list; return (int) n_list;
} }

View File

@ -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_len = size;
m->hdr->nlmsg_type = type; m->hdr->nlmsg_type = type;
*ret = m; *ret = TAKE_PTR(m);
m = NULL;
return 0; return 0;
} }

View File

@ -433,8 +433,7 @@ int socket_read_message(sd_netlink *rtnl) {
/* push the message onto the multi-part message stack */ /* push the message onto the multi-part message stack */
if (first) if (first)
m->next = first; m->next = first;
first = m; first = TAKE_PTR(m);
m = NULL;
} }
if (len > 0) if (len > 0)
@ -449,8 +448,7 @@ int socket_read_message(sd_netlink *rtnl) {
if (r < 0) if (r < 0)
return r; return r;
rtnl->rqueue[rtnl->rqueue_size++] = first; rtnl->rqueue[rtnl->rqueue_size++] = TAKE_PTR(first);
first = NULL;
if (multi_part && (i < rtnl->rqueue_partial_size)) { if (multi_part && (i < rtnl->rqueue_partial_size)) {
/* remove the message form the partial read queue */ /* 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 /* we only got a partial multi-part message, push it on the
partial read queue */ partial read queue */
if (i < rtnl->rqueue_partial_size) if (i < rtnl->rqueue_partial_size)
rtnl->rqueue_partial[i] = first; rtnl->rqueue_partial[i] = TAKE_PTR(first);
else { else {
r = rtnl_rqueue_partial_make_room(rtnl); r = rtnl_rqueue_partial_make_room(rtnl);
if (r < 0) if (r < 0)
return r; return r;
rtnl->rqueue_partial[rtnl->rqueue_partial_size++] = first; rtnl->rqueue_partial[rtnl->rqueue_partial_size++] = TAKE_PTR(first);
} }
first = NULL;
return 0; return 0;
} }

View File

@ -62,8 +62,7 @@ static int sd_netlink_new(sd_netlink **ret) {
* responses with notifications from the kernel */ * responses with notifications from the kernel */
rtnl->serial = 1; rtnl->serial = 1;
*ret = rtnl; *ret = TAKE_PTR(rtnl);
rtnl = NULL;
return 0; return 0;
} }
@ -90,8 +89,7 @@ int sd_netlink_new_from_netlink(sd_netlink **ret, int fd) {
rtnl->fd = fd; rtnl->fd = fd;
*ret = rtnl; *ret = TAKE_PTR(rtnl);
rtnl = NULL;
return 0; return 0;
} }
@ -133,8 +131,7 @@ int sd_netlink_open_fd(sd_netlink **ret, int fd) {
return r; return r;
} }
*ret = rtnl; *ret = TAKE_PTR(rtnl);
rtnl = NULL;
return 0; return 0;
} }
@ -425,8 +422,7 @@ static int process_running(sd_netlink *rtnl, sd_netlink_message **ret) {
} }
if (ret) { if (ret) {
*ret = m; *ret = TAKE_PTR(m);
m = NULL;
return 1; return 1;
} }
@ -669,10 +665,8 @@ int sd_netlink_call(sd_netlink *rtnl,
return 0; return 0;
} }
if (ret) { if (ret)
*ret = incoming; *ret = TAKE_PTR(incoming);
incoming = NULL;
}
return 1; return 1;
} }

View File

@ -73,8 +73,7 @@ _public_ struct udev_hwdb *udev_hwdb_new(struct udev *udev) {
} }
hwdb->refcount = 1; hwdb->refcount = 1;
hwdb->hwdb = hwdb_internal; hwdb->hwdb = TAKE_PTR(hwdb_internal);
hwdb_internal = NULL;
udev_list_init(udev, &hwdb->properties_list, true); udev_list_init(udev, &hwdb->properties_list, true);

View File

@ -666,8 +666,7 @@ int find_language_fallback(const char *lang, char **language) {
if (streq(lang, a[0])) { if (streq(lang, a[0])) {
assert(strv_length(a) == 2); assert(strv_length(a) == 2);
*language = a[1]; *language = TAKE_PTR(a[1]);
a[1] = NULL;
return 1; return 1;
} }
} }

View File

@ -660,8 +660,7 @@ static int connect_bus(Context *c, sd_event *event, sd_bus **_bus) {
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to attach bus to event loop: %m"); return log_error_errno(r, "Failed to attach bus to event loop: %m");
*_bus = bus; *_bus = TAKE_PTR(bus);
bus = NULL;
return 0; return 0;
} }

View File

@ -419,8 +419,7 @@ int seat_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***
} }
} }
*nodes = l; *nodes = TAKE_PTR(l);
l = NULL;
return 1; return 1;
} }

View File

@ -666,8 +666,7 @@ int session_node_enumerator(sd_bus *bus, const char *path, void *userdata, char
} }
} }
*nodes = l; *nodes = TAKE_PTR(l);
l = NULL;
return 1; return 1;
} }

View File

@ -354,8 +354,7 @@ int user_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***
} }
} }
*nodes = l; *nodes = TAKE_PTR(l);
l = NULL;
return 1; return 1;
} }

View File

@ -100,8 +100,8 @@ int user_new(User **out, Manager *m, uid_t uid, gid_t gid, const char *name) {
if (r < 0) if (r < 0)
return r; return r;
*out = u; *out = TAKE_PTR(u);
u = NULL;
return 0; return 0;
} }

View File

@ -507,8 +507,7 @@ int image_node_enumerator(sd_bus *bus, const char *path, void *userdata, char **
return r; return r;
} }
*nodes = l; *nodes = TAKE_PTR(l);
l = NULL;
return 1; return 1;
} }

View File

@ -522,8 +522,7 @@ static int container_bus_new(Machine *m, sd_bus_error *error, sd_bus **ret) {
if (r < 0) if (r < 0)
return r; return r;
*ret = bus; *ret = TAKE_PTR(bus);
bus = NULL;
break; break;
} }
@ -647,8 +646,7 @@ int bus_machine_method_open_shell(sd_bus_message *message, void *userdata, sd_bu
} else { } else {
if (!path_is_absolute(path)) if (!path_is_absolute(path))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Specified path '%s' is not absolute", path); return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Specified path '%s' is not absolute", path);
args = args_wire; args = TAKE_PTR(args_wire);
args_wire = NULL;
if (strv_isempty(args)) { if (strv_isempty(args)) {
args = strv_free(args); args = strv_free(args);
@ -1506,8 +1504,7 @@ int machine_send_create_reply(Machine *m, sd_bus_error *error) {
if (!m->create_message) if (!m->create_message)
return 0; return 0;
c = m->create_message; c = TAKE_PTR(m->create_message);
m->create_message = NULL;
if (error) if (error)
return sd_bus_reply_method_error(c, error); return sd_bus_reply_method_error(c, error);

View File

@ -124,9 +124,8 @@ static int manager_add_host_machine(Manager *m) {
t->leader = 1; t->leader = 1;
t->id = mid; t->id = mid;
t->root_directory = rd; t->root_directory = TAKE_PTR(rd);
t->unit = unit; t->unit = TAKE_PTR(unit);
rd = unit = NULL;
dual_timestamp_from_boottime_or_monotonic(&t->timestamp, 0); dual_timestamp_from_boottime_or_monotonic(&t->timestamp, 0);

View File

@ -626,15 +626,11 @@ int config_parse_wireguard_endpoint(const char *unit,
if (!port) if (!port)
return log_oom(); return log_oom();
endpoint->peer = peer; endpoint->peer = TAKE_PTR(peer);
endpoint->host = host; endpoint->host = TAKE_PTR(host);
endpoint->port = port; endpoint->port = TAKE_PTR(port);
endpoint->netdev = netdev_ref(data); endpoint->netdev = netdev_ref(data);
LIST_PREPEND(endpoints, w->unresolved_endpoints, endpoint); LIST_PREPEND(endpoints, w->unresolved_endpoints, endpoint);
peer = NULL;
host = NULL;
port = NULL;
endpoint = NULL; endpoint = NULL;
return 0; return 0;

View File

@ -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); qsort_safe(links, c, sizeof(LinkInfo), link_info_compare);
*ret = links; *ret = TAKE_PTR(links);
links = NULL;
return (int) c; 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); qsort_safe(links, c, sizeof(LinkInfo), link_info_compare);
*ret = links; *ret = TAKE_PTR(links);
links = NULL;
return (int) c; return (int) c;
} }

View File

@ -36,8 +36,7 @@ int address_label_new(AddressLabel **ret) {
if (!addrlabel) if (!addrlabel)
return -ENOMEM; return -ENOMEM;
*ret = addrlabel; *ret = TAKE_PTR(addrlabel);
addrlabel = NULL;
return 0; 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); label = hashmap_get(network->address_labels_by_section, n);
if (label) { if (label) {
*ret = label; *ret = TAKE_PTR(label);
label = NULL;
return 0; return 0;
} }
@ -85,8 +83,7 @@ static int address_label_new_static(Network *network, const char *filename, unsi
if (r < 0) if (r < 0)
return r; return r;
label->section = n; label->section = TAKE_PTR(n);
n = NULL;
r = hashmap_put(network->address_labels_by_section, label->section, label); r = hashmap_put(network->address_labels_by_section, label->section, label);
if (r < 0) 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); LIST_APPEND(labels, network->address_labels, label);
network->n_address_labels++; network->n_address_labels++;
*ret = label; *ret = TAKE_PTR(label);
label = NULL;
return 0; return 0;
} }

View File

@ -48,8 +48,7 @@ int address_new(Address **ret) {
address->cinfo.ifa_prefered = CACHE_INFO_INFINITY_LIFE_TIME; address->cinfo.ifa_prefered = CACHE_INFO_INFINITY_LIFE_TIME;
address->cinfo.ifa_valid = CACHE_INFO_INFINITY_LIFE_TIME; address->cinfo.ifa_valid = CACHE_INFO_INFINITY_LIFE_TIME;
*ret = address; *ret = TAKE_PTR(address);
address = NULL;
return 0; 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); address = hashmap_get(network->addresses_by_section, n);
if (address) { if (address) {
*ret = address; *ret = TAKE_PTR(address);
address = NULL;
return 0; return 0;
} }
@ -85,8 +83,7 @@ int address_new_static(Network *network, const char *filename, unsigned section_
return r; return r;
if (filename) { if (filename) {
address->section = n; address->section = TAKE_PTR(n);
n = NULL;
r = hashmap_put(network->addresses_by_section, address->section, address); r = hashmap_put(network->addresses_by_section, address->section, address);
if (r < 0) 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); LIST_APPEND(addresses, network->static_addresses, address);
network->n_static_addresses++; network->n_static_addresses++;
*ret = address; *ret = TAKE_PTR(address);
address = NULL;
return 0; return 0;
} }
@ -541,8 +537,7 @@ static int address_acquire(Link *link, Address *original, Address **ret) {
LIST_PREPEND(addresses, link->pool_addresses, na); LIST_PREPEND(addresses, link->pool_addresses, na);
*ret = na; *ret = TAKE_PTR(na);
na = NULL;
return 0; return 0;
} }

View File

@ -48,8 +48,7 @@ int fdb_entry_new_static(
if (section) { if (section) {
fdb_entry = hashmap_get(network->fdb_entries_by_section, UINT_TO_PTR(section)); fdb_entry = hashmap_get(network->fdb_entries_by_section, UINT_TO_PTR(section));
if (fdb_entry) { if (fdb_entry) {
*ret = fdb_entry; *ret = TAKE_PTR(fdb_entry);
fdb_entry = NULL;
return 0; return 0;
} }
@ -85,8 +84,7 @@ int fdb_entry_new_static(
} }
/* return allocated FDB structure. */ /* return allocated FDB structure. */
*ret = fdb_entry; *ret = TAKE_PTR(fdb_entry);
fdb_entry = NULL;
return 0; return 0;
} }

View File

@ -501,8 +501,7 @@ static int link_new(Manager *manager, sd_netlink_message *message, Link **ret) {
if (r < 0) if (r < 0)
return r; return r;
*ret = link; *ret = TAKE_PTR(link);
link = NULL;
return 0; return 0;
} }
@ -2973,8 +2972,7 @@ network_file_fail:
route->lifetime = lifetime; route->lifetime = lifetime;
sd_event_source_unref(route->expire); sd_event_source_unref(route->expire);
route->expire = expire; route->expire = TAKE_PTR(expire);
expire = NULL;
} }
} }

View File

@ -198,10 +198,9 @@ static int lldp_make_packet(
assert(p == (uint8_t*) packet + l); assert(p == (uint8_t*) packet + l);
*ret = packet; *ret = TAKE_PTR(packet);
*sz = l; *sz = l;
packet = NULL;
return 0; return 0;
} }

View File

@ -1444,8 +1444,7 @@ int manager_new(Manager **ret, sd_event *event) {
(void) routing_policy_load_rules(m->state_file, &m->rules_saved); (void) routing_policy_load_rules(m->state_file, &m->rules_saved);
*ret = m; *ret = TAKE_PTR(m);
m = NULL;
return 0; return 0;
} }

View File

@ -149,8 +149,7 @@ int prefix_new_static(Network *network, const char *filename,
if (section_line) { if (section_line) {
prefix = hashmap_get(network->prefixes_by_section, n); prefix = hashmap_get(network->prefixes_by_section, n);
if (prefix) { if (prefix) {
*ret = prefix; *ret = TAKE_PTR(prefix);
prefix = NULL;
return 0; return 0;
} }
@ -162,8 +161,7 @@ int prefix_new_static(Network *network, const char *filename,
return r; return r;
if (filename) { if (filename) {
prefix->section = n; prefix->section = TAKE_PTR(n);
n = NULL;
r = hashmap_put(network->prefixes_by_section, prefix->section, r = hashmap_put(network->prefixes_by_section, prefix->section,
prefix); prefix);
@ -175,8 +173,7 @@ int prefix_new_static(Network *network, const char *filename,
LIST_APPEND(prefixes, network->static_prefixes, prefix); LIST_APPEND(prefixes, network->static_prefixes, prefix);
network->n_static_prefixes++; network->n_static_prefixes++;
*ret = prefix; *ret = TAKE_PTR(prefix);
prefix = NULL;
return 0; return 0;
} }

View File

@ -76,8 +76,7 @@ int route_new(Route **ret) {
route->lifetime = USEC_INFINITY; route->lifetime = USEC_INFINITY;
route->quickack = -1; route->quickack = -1;
*ret = route; *ret = TAKE_PTR(route);
route = NULL;
return 0; 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); route = hashmap_get(network->routes_by_section, n);
if (route) { if (route) {
*ret = route; *ret = TAKE_PTR(route);
route = NULL;
return 0; return 0;
} }
@ -115,8 +113,7 @@ int route_new_static(Network *network, const char *filename, unsigned section_li
route->protocol = RTPROT_STATIC; route->protocol = RTPROT_STATIC;
if (filename) { if (filename) {
route->section = n; route->section = TAKE_PTR(n);
n = NULL;
r = hashmap_put(network->routes_by_section, route->section, route); r = hashmap_put(network->routes_by_section, route->section, route);
if (r < 0) 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); LIST_PREPEND(routes, network->static_routes, route);
network->n_static_routes++; network->n_static_routes++;
*ret = route; *ret = TAKE_PTR(route);
route = NULL;
return 0; return 0;
} }
@ -689,8 +685,7 @@ int route_configure(
} }
sd_event_source_unref(route->expire); sd_event_source_unref(route->expire);
route->expire = expire; route->expire = TAKE_PTR(expire);
expire = NULL;
return 0; return 0;
} }

View File

@ -406,8 +406,7 @@ static int routing_policy_rule_new_static(Network *network, const char *filename
rule = hashmap_get(network->rules_by_section, n); rule = hashmap_get(network->rules_by_section, n);
if (rule) { if (rule) {
*ret = rule; *ret = TAKE_PTR(rule);
rule = NULL;
return 0; return 0;
} }
@ -427,8 +426,7 @@ static int routing_policy_rule_new_static(Network *network, const char *filename
LIST_APPEND(rules, network->rules, rule); LIST_APPEND(rules, network->rules, rule);
network->n_rules++; network->n_rules++;
*ret = rule; *ret = TAKE_PTR(rule);
rule = NULL;
return 0; return 0;
} }

View File

@ -303,8 +303,7 @@ int manager_new(Manager **ret, char **interfaces, char **ignore, usec_t timeout)
if (r < 0) if (r < 0)
return r; return r;
*ret = m; *ret = TAKE_PTR(m);
m = NULL;
return 0; return 0;
} }

View File

@ -239,8 +239,7 @@ int expose_port_watch_rtnl(
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to add to even loop: %m"); return log_error_errno(r, "Failed to add to even loop: %m");
*ret = rtnl; *ret = TAKE_PTR(rtnl);
rtnl = NULL;
return 0; return 0;
} }

View File

@ -282,10 +282,9 @@ int tmpfs_mount_parse(CustomMount **l, unsigned *n, const char *s) {
if (!m) if (!m)
return -ENOMEM; return -ENOMEM;
m->destination = path; m->destination = TAKE_PTR(path);
m->options = opts; m->options = TAKE_PTR(opts);
path = opts = NULL;
return 0; return 0;
} }
@ -341,14 +340,11 @@ int overlay_mount_parse(CustomMount **l, unsigned *n, const char *s, bool read_o
if (!m) if (!m)
return -ENOMEM; return -ENOMEM;
m->destination = destination; m->destination = TAKE_PTR(destination);
m->source = upper; m->source = TAKE_PTR(upper);
m->lower = lower; m->lower = TAKE_PTR(lower);
m->read_only = read_only; m->read_only = read_only;
upper = destination = NULL;
lower = NULL;
return 0; return 0;
} }
@ -867,8 +863,7 @@ static int get_process_controllers(Set **ret) {
return r; return r;
} }
*ret = controllers; *ret = TAKE_PTR(controllers);
controllers = NULL;
return 0; return 0;
} }

View File

@ -175,8 +175,7 @@ static int shift_acl(acl_t acl, uid_t shift, acl_t *ret) {
return -errno; return -errno;
} }
*ret = copy; *ret = TAKE_PTR(copy);
copy = NULL;
return !!*ret; return !!*ret;
} }

View File

@ -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) if (s->userns_chown >= 0 && s->userns_mode == _USER_NAMESPACE_MODE_INVALID)
s->userns_mode = USER_NAMESPACE_NO; s->userns_mode = USER_NAMESPACE_NO;
*ret = s; *ret = TAKE_PTR(s);
s = NULL;
return 0; return 0;
} }

View File

@ -243,10 +243,8 @@ int change_uid_gid(const char *user, char **_home) {
if (setresuid(uid, uid, uid) < 0) if (setresuid(uid, uid, uid) < 0)
return log_error_errno(errno, "setresuid() failed: %m"); return log_error_errno(errno, "setresuid() failed: %m");
if (_home) { if (_home)
*_home = home; *_home = TAKE_PTR(home);
home = NULL;
}
return 0; return 0;
} }

View File

@ -3074,8 +3074,7 @@ static int load_settings(void) {
f = fopen(j, "re"); f = fopen(j, "re");
if (f) { if (f) {
p = j; p = TAKE_PTR(j);
j = NULL;
/* By default, we trust configuration from /etc and /run */ /* By default, we trust configuration from /etc and /run */
if (arg_settings_trusted < 0) if (arg_settings_trusted < 0)
@ -3130,8 +3129,7 @@ static int load_settings(void) {
arg_start_mode = settings->start_mode; arg_start_mode = settings->start_mode;
strv_free(arg_parameters); strv_free(arg_parameters);
arg_parameters = settings->parameters; arg_parameters = TAKE_PTR(settings->parameters);
settings->parameters = NULL;
} }
if ((arg_settings_mask & SETTING_PIVOT_ROOT) == 0 && 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 && if ((arg_settings_mask & SETTING_WORKING_DIRECTORY) == 0 &&
settings->working_directory) { settings->working_directory)
free(arg_chdir); free_and_replace(arg_chdir, settings->working_directory);
arg_chdir = settings->working_directory;
settings->working_directory = NULL;
}
if ((arg_settings_mask & SETTING_ENVIRONMENT) == 0 && if ((arg_settings_mask & SETTING_ENVIRONMENT) == 0 &&
settings->environment) { settings->environment) {
strv_free(arg_setenv); strv_free(arg_setenv);
arg_setenv = settings->environment; arg_setenv = TAKE_PTR(settings->environment);
settings->environment = NULL;
} }
if ((arg_settings_mask & SETTING_USER) == 0 && if ((arg_settings_mask & SETTING_USER) == 0 &&
settings->user) { settings->user)
free(arg_user); free_and_replace(arg_user, settings->user);
arg_user = settings->user;
settings->user = NULL;
}
if ((arg_settings_mask & SETTING_CAPABILITY) == 0) { if ((arg_settings_mask & SETTING_CAPABILITY) == 0) {
uint64_t plus; 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); log_warning("Ignoring TemporaryFileSystem=, Bind= and BindReadOnly= settings, file %s is not trusted.", p);
else { else {
custom_mount_free_all(arg_custom_mounts, arg_n_custom_mounts); 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; arg_n_custom_mounts = settings->n_custom_mounts;
settings->custom_mounts = NULL;
settings->n_custom_mounts = 0; settings->n_custom_mounts = 0;
} }
} }
@ -3234,28 +3223,19 @@ static int load_settings(void) {
arg_private_network = settings_private_network(settings); arg_private_network = settings_private_network(settings);
strv_free(arg_network_interfaces); strv_free(arg_network_interfaces);
arg_network_interfaces = settings->network_interfaces; arg_network_interfaces = TAKE_PTR(settings->network_interfaces);
settings->network_interfaces = NULL;
strv_free(arg_network_macvlan); strv_free(arg_network_macvlan);
arg_network_macvlan = settings->network_macvlan; arg_network_macvlan = TAKE_PTR(settings->network_macvlan);
settings->network_macvlan = NULL;
strv_free(arg_network_ipvlan); strv_free(arg_network_ipvlan);
arg_network_ipvlan = settings->network_ipvlan; arg_network_ipvlan = TAKE_PTR(settings->network_ipvlan);
settings->network_ipvlan = NULL;
strv_free(arg_network_veth_extra); strv_free(arg_network_veth_extra);
arg_network_veth_extra = settings->network_veth_extra; arg_network_veth_extra = TAKE_PTR(settings->network_veth_extra);
settings->network_veth_extra = NULL;
free(arg_network_bridge); free_and_replace(arg_network_bridge, settings->network_bridge);
arg_network_bridge = settings->network_bridge; free_and_replace(arg_network_zone, settings->network_zone);
settings->network_bridge = NULL;
free(arg_network_zone);
arg_network_zone = settings->network_zone;
settings->network_zone = NULL;
} }
} }
@ -3266,8 +3246,7 @@ static int load_settings(void) {
log_warning("Ignoring Port= setting, file %s is not trusted.", p); log_warning("Ignoring Port= setting, file %s is not trusted.", p);
else { else {
expose_port_free_all(arg_expose_ports); expose_port_free_all(arg_expose_ports);
arg_expose_ports = settings->expose_ports; arg_expose_ports = TAKE_PTR(settings->expose_ports);
settings->expose_ports = NULL;
} }
} }
@ -3295,10 +3274,8 @@ static int load_settings(void) {
strv_free(arg_syscall_whitelist); strv_free(arg_syscall_whitelist);
strv_free(arg_syscall_blacklist); strv_free(arg_syscall_blacklist);
arg_syscall_whitelist = settings->syscall_whitelist; arg_syscall_whitelist = TAKE_PTR(settings->syscall_whitelist);
arg_syscall_blacklist = settings->syscall_blacklist; arg_syscall_blacklist = TAKE_PTR(settings->syscall_blacklist);
settings->syscall_whitelist = settings->syscall_blacklist = NULL;
} }
} }
@ -3917,9 +3894,7 @@ int main(int argc, char *argv[]) {
goto finish; goto finish;
} }
free(arg_directory); free_and_replace(arg_directory, np);
arg_directory = np;
np = NULL;
remove_directory = true; remove_directory = true;
@ -4009,9 +3984,7 @@ int main(int argc, char *argv[]) {
goto finish; goto finish;
} }
free(arg_image); free_and_replace(arg_image, np);
arg_image = np;
np = NULL;
remove_image = true; remove_image = true;
} else { } else {

Some files were not shown because too many files have changed in this diff Show More