diff --git a/src/core/unit.c b/src/core/unit.c index 7685ab1996b..e6c5a45dcf2 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -646,13 +646,11 @@ static void unit_clear_dependencies(Unit *u) { static void unit_remove_transient(Unit *u) { assert(u); + assert(u->manager); if (!u->transient) return; - if (u->fragment_path) - (void) unlink(u->fragment_path); - STRV_FOREACH(i, u->dropin_paths) { _cleanup_free_ char *p = NULL, *pp = NULL; @@ -669,6 +667,17 @@ static void unit_remove_transient(Unit *u) { (void) unlink(*i); (void) rmdir(p); } + + if (u->fragment_path) { + (void) unlink(u->fragment_path); + (void) unit_file_remove_from_name_map( + &u->manager->lookup_paths, + &u->manager->unit_cache_timestamp_hash, + &u->manager->unit_id_map, + &u->manager->unit_name_map, + &u->manager->unit_path_cache, + u->fragment_path); + } } static void unit_free_mounts_for(Unit *u) {