tree-wide: take benefit of the fact that hashmap_free() returns NULL

And set_free() too.

Another Coccinelle patch.
This commit is contained in:
Lennart Poettering 2015-09-09 23:12:07 +02:00
parent 6796073e33
commit 525d3cc746
10 changed files with 69 additions and 33 deletions

View File

@ -0,0 +1,54 @@
@@
expression p;
@@
- set_free(p);
- p = NULL;
+ p = set_free(p);
@@
expression p;
@@
- if (p)
- set_free(p);
- p = NULL;
+ p = set_free(p);
@@
expression p;
@@
- if (p) {
- set_free(p);
- p = NULL;
- }
+ p = set_free(p);
@@
expression p;
@@
- if (p)
- set_free(p);
+ set_free(p);
@@
expression p;
@@
- hashmap_free(p);
- p = NULL;
+ p = hashmap_free(p);
@@
expression p;
@@
- if (p)
- hashmap_free(p);
- p = NULL;
+ p = hashmap_free(p);
@@
expression p;
@@
- if (p) {
- hashmap_free(p);
- p = NULL;
- }
+ p = hashmap_free(p);
@@
expression p;
@@
- if (p)
- hashmap_free(p);
+ hashmap_free(p);

View File

@ -129,10 +129,8 @@ static void automount_done(Unit *u) {
a->where = mfree(a->where);
set_free(a->tokens);
a->tokens = NULL;
set_free(a->expire_tokens);
a->expire_tokens = NULL;
a->tokens = set_free(a->tokens);
a->expire_tokens = set_free(a->expire_tokens);
a->expire_event_source = sd_event_source_unref(a->expire_event_source);
}

View File

@ -1055,8 +1055,7 @@ void bus_done(Manager *m) {
while ((b = set_steal_first(m->private_buses)))
destroy_bus(m, &b);
set_free(m->private_buses);
m->private_buses = NULL;
m->private_buses = set_free(m->private_buses);
m->subscribed = sd_bus_track_unref(m->subscribed);
m->deserialized_subscribed = strv_free(m->deserialized_subscribed);

View File

@ -594,8 +594,7 @@ static void device_shutdown(Manager *m) {
m->udev_monitor = NULL;
}
hashmap_free(m->devices_by_sysfs);
m->devices_by_sysfs = NULL;
m->devices_by_sysfs = hashmap_free(m->devices_by_sysfs);
}
static int device_enumerate(Manager *m) {

View File

@ -2025,14 +2025,9 @@ void exec_context_done(ExecContext *c) {
c->selinux_context = mfree(c->selinux_context);
c->apparmor_profile = mfree(c->apparmor_profile);
set_free(c->syscall_filter);
c->syscall_filter = NULL;
set_free(c->syscall_archs);
c->syscall_archs = NULL;
set_free(c->address_families);
c->address_families = NULL;
c->syscall_filter = set_free(c->syscall_filter);
c->syscall_archs = set_free(c->syscall_archs);
c->address_families = set_free(c->address_families);
c->runtime_directory = strv_free(c->runtime_directory);

View File

@ -2302,8 +2302,7 @@ int config_parse_syscall_filter(
if (isempty(rvalue)) {
/* Empty assignment resets the list */
set_free(c->syscall_filter);
c->syscall_filter = NULL;
c->syscall_filter = set_free(c->syscall_filter);
c->syscall_whitelist = false;
return 0;
}
@ -2401,8 +2400,7 @@ int config_parse_syscall_archs(
int r;
if (isempty(rvalue)) {
set_free(*archs);
*archs = NULL;
*archs = set_free(*archs);
return 0;
}
@ -2498,8 +2496,7 @@ int config_parse_address_families(
if (isempty(rvalue)) {
/* Empty assignment resets the list */
set_free(c->address_families);
c->address_families = NULL;
c->address_families = set_free(c->address_families);
c->address_families_whitelist = false;
return 0;
}

View File

@ -1846,8 +1846,7 @@ finish:
arg_default_environment = strv_free(arg_default_environment);
set_free(arg_syscall_archs);
arg_syscall_archs = NULL;
arg_syscall_archs = set_free(arg_syscall_archs);
mac_selinux_finish();

View File

@ -1254,8 +1254,7 @@ static void swap_shutdown(Manager *m) {
m->proc_swaps = safe_fclose(m->proc_swaps);
hashmap_free(m->swaps_by_devnode);
m->swaps_by_devnode = NULL;
m->swaps_by_devnode = hashmap_free(m->swaps_by_devnode);
}
static int swap_enumerate(Manager *m) {

View File

@ -673,8 +673,7 @@ static void merge_dependencies(Unit *u, Unit *other, const char *other_id, UnitD
/* The move cannot fail. The caller must have performed a reservation. */
assert_se(complete_move(&u->dependencies[d], &other->dependencies[d]) == 0);
set_free(other->dependencies[d]);
other->dependencies[d] = NULL;
other->dependencies[d] = set_free(other->dependencies[d]);
}
int unit_merge(Unit *u, Unit *other) {

View File

@ -90,11 +90,8 @@ void dns_zone_flush(DnsZone *z) {
assert(hashmap_size(z->by_key) == 0);
assert(hashmap_size(z->by_name) == 0);
hashmap_free(z->by_key);
z->by_key = NULL;
hashmap_free(z->by_name);
z->by_name = NULL;
z->by_key = hashmap_free(z->by_key);
z->by_name = hashmap_free(z->by_name);
}
static DnsZoneItem* dns_zone_get(DnsZone *z, DnsResourceRecord *rr) {