Add set_consume which always takes ownership

Freeing in error path is the common pattern with set_put().
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2013-04-24 00:25:04 -04:00
parent c79bb9e4e2
commit ef42202ac8
14 changed files with 40 additions and 59 deletions
+2 -4
View File
@@ -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)
+2 -4
View File
@@ -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;
}
}
}
+2 -4
View File
@@ -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);
+1 -2
View File
@@ -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;
}
}