diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-04-22 23:12:15 -0400 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-04-24 00:25:04 -0400 |
commit | ef42202ac8ed27e7ff1fc90ef8bc2590046dff25 (patch) | |
tree | b1646eeb8ef5070337ae701ffb4abf0e398640ad /src/core | |
parent | c79bb9e4e2e5b96b2ae2c432bf8b0ff9674fce60 (diff) |
Add set_consume which always takes ownership
Freeing in error path is the common pattern with set_put().
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/dbus-manager.c | 6 | ||||
-rw-r--r-- | src/core/load-fragment.c | 6 | ||||
-rw-r--r-- | src/core/manager.c | 6 | ||||
-rw-r--r-- | src/core/mount-setup.c | 3 |
4 files changed, 7 insertions, 14 deletions
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index d767dd5236..1f5a7d94fd 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -1186,11 +1186,9 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, if (!client) goto oom; - r = set_put(s, client); - if (r < 0) { - free(client); + r = set_consume(s, client); + if (r < 0) return bus_send_error_reply(connection, message, NULL, r); - } reply = dbus_message_new_method_return(message); if (!reply) diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 0571d517b0..3d23372630 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -2095,11 +2095,9 @@ static int open_follow(char **filename, FILE **_f, Set *names, char **_final) { if (!id) return -ENOMEM; - r = set_put(names, id); - if (r < 0) { - free(id); + r = set_consume(names, id); + if (r < 0) return r; - } } } diff --git a/src/core/manager.c b/src/core/manager.c index 208b240ba1..b1a22890fb 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -806,11 +806,9 @@ static void manager_build_unit_path_cache(Manager *m) { goto fail; } - r = set_put(m->unit_path_cache, p); - if (r < 0) { - free(p); + r = set_consume(m->unit_path_cache, p); + if (r < 0) goto fail; - } } closedir(d); diff --git a/src/core/mount-setup.c b/src/core/mount-setup.c index 89adb0b4a3..b841f478c3 100644 --- a/src/core/mount-setup.c +++ b/src/core/mount-setup.c @@ -251,10 +251,9 @@ int mount_cgroup_controllers(char ***join_controllers) { continue; } - r = set_put(controllers, controller); + r = set_consume(controllers, controller); if (r < 0) { log_error("Failed to add controller to set."); - free(controller); goto finish; } } |