util/apparmor: allow repeated calls to set_bus_type()
Allow repeated calls to set_bus_type() to set or clear previous types.
@@ -169,11 +169,19 @@ BusAppArmorRegistry *bus_apparmor_registry_unref(BusAppArmorRegistry *registry)
}
int bus_apparmor_set_bus_type(BusAppArmorRegistry *registry, const char *bustype) {
- c_assert(!registry->bustype);
+ char *dup;
- registry->bustype = strdup(bustype);
- if (!registry->bustype)
+ if (bustype) {
+ dup = strdup(bustype);
+ if (!dup)
return error_origin(-ENOMEM);
+ } else {
+ dup = NULL;
+ }
+
+ free(registry->bustype);
+ registry->bustype = dup;
+
return 0;
}
