Add set_consume which always takes ownership
Freeing in error path is the common pattern with set_put().
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user