From: David Tardon Date: Wed, 24 May 2023 12:21:04 +0000 (+0200) Subject: tree-wide: use free_and_replace() more X-Git-Tag: v254-rc1~393^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d6f2cd671c3699849edbfacc60e966e400fc663e;p=thirdparty%2Fsystemd.git tree-wide: use free_and_replace() more --- diff --git a/src/basic/string-util.c b/src/basic/string-util.c index c74ee67dfec..d4141968df3 100644 --- a/src/basic/string-util.c +++ b/src/basic/string-util.c @@ -955,8 +955,7 @@ int free_and_strdup(char **p, const char *s) { } else t = NULL; - free(*p); - *p = t; + free_and_replace(*p, t); return 1; } diff --git a/src/basic/strv.c b/src/basic/strv.c index 822dadeeb4a..deadb9909e9 100644 --- a/src/basic/strv.c +++ b/src/basic/strv.c @@ -723,8 +723,7 @@ char** strv_shell_escape(char **l, const char *bad) { if (!v) return NULL; - free(*s); - *s = v; + free_and_replace(*s, v); } return l; diff --git a/src/coredump/coredump-vacuum.c b/src/coredump/coredump-vacuum.c index c6e201ecf20..7e0c98cb7d4 100644 --- a/src/coredump/coredump-vacuum.c +++ b/src/coredump/coredump-vacuum.c @@ -187,8 +187,7 @@ int coredump_vacuum(int exclude_fd, uint64_t keep_free, uint64_t max_use) { if (!n) return log_oom(); - free(c->oldest_file); - c->oldest_file = n; + free_and_replace(c->oldest_file, n); c->oldest_mtime = t; } diff --git a/src/journal/journald-native.c b/src/journal/journald-native.c index ca23508454f..4888c38fdb0 100644 --- a/src/journal/journald-native.c +++ b/src/journal/journald-native.c @@ -66,20 +66,16 @@ static void server_process_entry_meta( char *t; t = memdup_suffix0(p + 18, l - 18); - if (t) { - free(*identifier); - *identifier = t; - } + if (t) + free_and_replace(*identifier, t); } else if (l >= 8 && startswith(p, "MESSAGE=")) { char *t; t = memdup_suffix0(p + 8, l - 8); - if (t) { - free(*message); - *message = t; - } + if (t) + free_and_replace(*message, t); } else if (l > STRLEN("OBJECT_PID=") && l < STRLEN("OBJECT_PID=") + DECIMAL_STR_MAX(pid_t) && diff --git a/src/libsystemd-network/lldp-neighbor.c b/src/libsystemd-network/lldp-neighbor.c index 6672409d753..af61c9b096b 100644 --- a/src/libsystemd-network/lldp-neighbor.c +++ b/src/libsystemd-network/lldp-neighbor.c @@ -159,8 +159,7 @@ static int parse_string(sd_lldp_rx *lldp_rx, char **s, const void *q, size_t n) if (!k) return log_oom_debug(); - free(*s); - *s = k; + free_and_replace(*s, k); return 1; } diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c index 02c6a6e0d79..b0a36324121 100644 --- a/src/libsystemd-network/sd-dhcp-lease.c +++ b/src/libsystemd-network/sd-dhcp-lease.c @@ -451,8 +451,7 @@ static int lease_parse_in_addrs(const uint8_t *option, size_t len, struct in_add if (!addresses) return -ENOMEM; - free(*ret); - *ret = addresses; + free_and_replace(*ret, addresses); *n_ret = n_addresses; } @@ -795,8 +794,7 @@ int dhcp_lease_parse_options(uint8_t code, uint8_t len, const void *option, void if (!p) return -ENOMEM; - free(lease->vendor_specific); - lease->vendor_specific = p; + free_and_replace(lease->vendor_specific, p); } lease->vendor_specific_len = len; @@ -1458,8 +1456,7 @@ int dhcp_lease_set_client_id(sd_dhcp_lease *lease, const void *client_id, size_t if (!p) return -ENOMEM; - free(lease->client_id); - lease->client_id = p; + free_and_replace(lease->client_id, p); lease->client_id_len = client_id_len; } diff --git a/src/libsystemd/sd-bus/bus-socket.c b/src/libsystemd/sd-bus/bus-socket.c index 741d54cabdf..e4e19972649 100644 --- a/src/libsystemd/sd-bus/bus-socket.c +++ b/src/libsystemd/sd-bus/bus-socket.c @@ -337,8 +337,7 @@ static int bus_socket_auth_write(sd_bus *b, const char *t) { b->auth_iovec[0].iov_base = p; b->auth_iovec[0].iov_len += l; - free(b->auth_buffer); - b->auth_buffer = p; + free_and_replace(b->auth_buffer, p); b->auth_index = 0; return 0; } @@ -868,8 +867,7 @@ static int bus_socket_inotify_setup(sd_bus *b) { goto fail; } - free(absolute); - absolute = c; + free_and_replace(absolute, c); max_follow--; } diff --git a/src/libsystemd/sd-resolve/sd-resolve.c b/src/libsystemd/sd-resolve/sd-resolve.c index 841b8630243..dcd3547f8b9 100644 --- a/src/libsystemd/sd-resolve/sd-resolve.c +++ b/src/libsystemd/sd-resolve/sd-resolve.c @@ -1109,8 +1109,7 @@ static void resolve_freeaddrinfo(struct addrinfo *ai) { free(ai->ai_addr); free(ai->ai_canonname); - free(ai); - ai = next; + free_and_replace(ai, next); } } diff --git a/src/shared/calendarspec.c b/src/shared/calendarspec.c index 86a6d3f6080..78902dfbda6 100644 --- a/src/shared/calendarspec.c +++ b/src/shared/calendarspec.c @@ -37,8 +37,7 @@ assert_cc(INT_MAX >= USEC_PER_SEC); static CalendarComponent* chain_free(CalendarComponent *c) { while (c) { CalendarComponent *n = c->next; - free(c); - c = n; + free_and_replace(c, n); } return NULL; }