summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Lockyer <thisisdaniellockyer@gmail.com>2017-11-24 11:33:41 +0100
committerDaniel Lockyer <thisisdaniellockyer@gmail.com>2017-11-24 11:33:41 +0100
commitf9ecfd3bbed396d744373dd6c8876b7211eac594 (patch)
tree036c4d7498abc62984d3d1daf8e6eba080943da7
parentReplace free and return NULL with return mfree (diff)
downloadsystemd-f9ecfd3bbed396d744373dd6c8876b7211eac594.tar.xz
systemd-f9ecfd3bbed396d744373dd6c8876b7211eac594.zip
Replace free and reassignment with free_and_replace
-rw-r--r--src/cryptsetup/cryptsetup-generator.c4
-rw-r--r--src/import/import-raw.c4
-rw-r--r--src/import/pull-raw.c4
-rw-r--r--src/libsystemd-network/dhcp-option.c4
-rw-r--r--src/libsystemd-network/sd-dhcp-lease.c8
-rw-r--r--src/libsystemd/sd-bus/sd-bus.c4
-rw-r--r--src/libsystemd/sd-device/device-private.c8
-rw-r--r--src/libsystemd/sd-device/sd-device.c28
-rw-r--r--src/locale/keymap-util.c4
-rw-r--r--src/nspawn/nspawn-settings.c4
-rw-r--r--src/shared/machine-image.c9
-rw-r--r--src/timedate/timedated.c4
12 files changed, 21 insertions, 64 deletions
diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c
index 7918c89564..3f7222a8aa 100644
--- a/src/cryptsetup/cryptsetup-generator.c
+++ b/src/cryptsetup/cryptsetup-generator.c
@@ -337,9 +337,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
d->create = arg_whitelist = true;
- free(d->name);
- d->name = uuid_value;
- uuid_value = NULL;
+ free_and_replace(d->name, uuid_value);
} else
log_warning("Failed to parse luks name switch %s. Ignoring.", value);
}
diff --git a/src/import/import-raw.c b/src/import/import-raw.c
index 6f4313420a..f117c94da2 100644
--- a/src/import/import-raw.c
+++ b/src/import/import-raw.c
@@ -207,9 +207,7 @@ static int raw_import_maybe_convert_qcow2(RawImport *i) {
}
(void) unlink(i->temp_path);
- free(i->temp_path);
- i->temp_path = t;
- t = NULL;
+ free_and_replace(i->temp_path, t);
safe_close(i->output_fd);
i->output_fd = converted_fd;
diff --git a/src/import/pull-raw.c b/src/import/pull-raw.c
index 8cab72495c..880cb84ba8 100644
--- a/src/import/pull-raw.c
+++ b/src/import/pull-raw.c
@@ -269,9 +269,7 @@ static int raw_pull_maybe_convert_qcow2(RawPull *i) {
}
(void) unlink(i->temp_path);
- free(i->temp_path);
- i->temp_path = t;
- t = NULL;
+ free_and_replace(i->temp_path, t);
safe_close(i->raw_job->disk_fd);
i->raw_job->disk_fd = converted_fd;
diff --git a/src/libsystemd-network/dhcp-option.c b/src/libsystemd-network/dhcp-option.c
index 19fc525866..0489579e7f 100644
--- a/src/libsystemd-network/dhcp-option.c
+++ b/src/libsystemd-network/dhcp-option.c
@@ -191,9 +191,7 @@ static int parse_options(const uint8_t options[], size_t buflen, uint8_t *overlo
if (!ascii_is_valid(string))
return -EINVAL;
- free(*error_message);
- *error_message = string;
- string = NULL;
+ free_and_replace(*error_message, string);
}
break;
diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c
index ec5ecaeabc..7063bd986e 100644
--- a/src/libsystemd-network/sd-dhcp-lease.c
+++ b/src/libsystemd-network/sd-dhcp-lease.c
@@ -393,9 +393,7 @@ static int lease_parse_domain(const uint8_t *option, size_t len, char **ret) {
if (dns_name_is_root(normalized))
return -EINVAL;
- free(*ret);
- *ret = normalized;
- normalized = NULL;
+ free_and_replace(*ret, normalized);
return 0;
}
@@ -684,9 +682,7 @@ int dhcp_lease_parse_options(uint8_t code, uint8_t len, const void *option, void
return 0;
}
- free(lease->timezone);
- lease->timezone = tz;
- tz = NULL;
+ free_and_replace(lease->timezone, tz);
break;
}
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
index 26ca669655..5fb15a7aaf 100644
--- a/src/libsystemd/sd-bus/sd-bus.c
+++ b/src/libsystemd/sd-bus/sd-bus.c
@@ -786,9 +786,7 @@ static int parse_container_unix_address(sd_bus *b, const char **p, char **guid)
if (!machine_name_is_valid(machine))
return -EINVAL;
- free(b->machine);
- b->machine = machine;
- machine = NULL;
+ free_and_replace(b->machine, machine);
} else {
b->machine = mfree(b->machine);
}
diff --git a/src/libsystemd/sd-device/device-private.c b/src/libsystemd/sd-device/device-private.c
index 587908b190..424965ecd5 100644
--- a/src/libsystemd/sd-device/device-private.c
+++ b/src/libsystemd/sd-device/device-private.c
@@ -678,13 +678,9 @@ static int device_update_properties_bufs(sd_device *device) {
i++;
}
- free(device->properties_nulstr);
- device->properties_nulstr = buf_nulstr;
- buf_nulstr = NULL;
+ free_and_replace(device->properties_nulstr, buf_nulstr);
device->properties_nulstr_len = nulstr_len;
- free(device->properties_strv);
- device->properties_strv = buf_strv;
- buf_strv = NULL;
+ free_and_replace(device->properties_strv, buf_strv);
device->properties_buf_outdated = false;
diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c
index b278eefa20..f8b9f9e3b0 100644
--- a/src/libsystemd/sd-device/sd-device.c
+++ b/src/libsystemd/sd-device/sd-device.c
@@ -215,9 +215,7 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) {
if (r < 0)
return r;
- free(device->syspath);
- device->syspath = syspath;
- syspath = NULL;
+ free_and_replace(device->syspath, syspath);
device->devpath = devpath;
@@ -347,9 +345,7 @@ int device_set_devtype(sd_device *device, const char *_devtype) {
if (r < 0)
return r;
- free(device->devtype);
- device->devtype = devtype;
- devtype = NULL;
+ free_and_replace(device->devtype, devtype);
return 0;
}
@@ -394,9 +390,7 @@ int device_set_devname(sd_device *device, const char *_devname) {
if (r < 0)
return r;
- free(device->devname);
- device->devname = devname;
- devname = NULL;
+ free_and_replace(device->devname, devname);
return 0;
}
@@ -761,9 +755,7 @@ int device_set_subsystem(sd_device *device, const char *_subsystem) {
if (r < 0)
return r;
- free(device->subsystem);
- device->subsystem = subsystem;
- subsystem = NULL;
+ free_and_replace(device->subsystem, subsystem);
device->subsystem_set = true;
@@ -786,9 +778,7 @@ static int device_set_drivers_subsystem(sd_device *device, const char *_subsyste
if (r < 0)
return r;
- free(device->driver_subsystem);
- device->driver_subsystem = subsystem;
- subsystem = NULL;
+ free_and_replace(device->driver_subsystem, subsystem);
return 0;
}
@@ -936,9 +926,7 @@ int device_set_driver(sd_device *device, const char *_driver) {
if (r < 0)
return r;
- free(device->driver);
- device->driver = driver;
- driver = NULL;
+ free_and_replace(device->driver, driver);
device->driver_set = true;
@@ -1045,9 +1033,7 @@ static int device_set_sysname(sd_device *device) {
if (len == 0)
sysnum = NULL;
- free(device->sysname);
- device->sysname = sysname;
- sysname = NULL;
+ free_and_replace(device->sysname, sysname);
device->sysnum = sysnum;
diff --git a/src/locale/keymap-util.c b/src/locale/keymap-util.c
index 1140ce299c..2457f8705c 100644
--- a/src/locale/keymap-util.c
+++ b/src/locale/keymap-util.c
@@ -201,9 +201,7 @@ static int x11_read_data(Context *c) {
p = &c->x11_options;
if (p) {
- free(*p);
- *p = a[2];
- a[2] = NULL;
+ free_and_replace(*p, a[2]);
}
}
diff --git a/src/nspawn/nspawn-settings.c b/src/nspawn/nspawn-settings.c
index 2c9a8f6b44..a1518a6e81 100644
--- a/src/nspawn/nspawn-settings.c
+++ b/src/nspawn/nspawn-settings.c
@@ -403,9 +403,7 @@ int config_parse_network_zone(
return 0;
}
- free(settings->network_zone);
- settings->network_zone = j;
- j = NULL;
+ free_and_replace(settings->network_zone, j);
return 0;
}
diff --git a/src/shared/machine-image.c b/src/shared/machine-image.c
index 7676a93e8b..5b6260cbb8 100644
--- a/src/shared/machine-image.c
+++ b/src/shared/machine-image.c
@@ -649,13 +649,8 @@ int image_rename(Image *i, const char *new_name) {
if (file_attr & FS_IMMUTABLE_FL)
(void) chattr_path(new_path, FS_IMMUTABLE_FL, FS_IMMUTABLE_FL);
- free(i->path);
- i->path = new_path;
- new_path = NULL;
-
- free(i->name);
- i->name = nn;
- nn = NULL;
+ free_and_replace(i->path, new_path);
+ free_and_replace(i->name, nn);
STRV_FOREACH(j, settings) {
r = rename_auxiliary_file(*j, new_name, ".nspawn");
diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index bd35451ecb..a55a929a49 100644
--- a/src/timedate/timedated.c
+++ b/src/timedate/timedated.c
@@ -75,9 +75,7 @@ static int context_read_data(Context *c) {
else if (r < 0)
log_warning_errno(r, "Failed to get target of /etc/localtime: %m");
- free(c->zone);
- c->zone = t;
- t = NULL;
+ free_and_replace(c->zone, t);
c->local_rtc = clock_is_localtime(NULL) > 0;