core: cleanup unit's dropin directories from global cache
When user creates dropin files via API (e.g. systemctl set-property ...)
we put the dropin directory path into unit_path_cache. Drop those
directories from the cache in unit_free() and prevent memory leak.
Follow-up for fce94c5c56.
This commit is contained in:
committed by
Mike Yuan
parent
c6b2ab09e7
commit
0c98e432d1
@@ -677,6 +677,8 @@ static void unit_remove_transient(Unit *u) {
|
||||
if (!u->transient)
|
||||
return;
|
||||
|
||||
const char *dropin_directory = strjoina(u->id, ".d");
|
||||
|
||||
STRV_FOREACH(i, u->dropin_paths) {
|
||||
_cleanup_free_ char *p = NULL, *pp = NULL;
|
||||
|
||||
@@ -690,6 +692,10 @@ static void unit_remove_transient(Unit *u) {
|
||||
if (!path_equal(u->manager->lookup_paths.transient, pp))
|
||||
continue;
|
||||
|
||||
/* Drop the transient drop-in directory also from unit path cache. */
|
||||
if (path_equal(last_path_component(p), dropin_directory))
|
||||
free(set_remove(u->manager->unit_path_cache, p));
|
||||
|
||||
(void) unlink(*i);
|
||||
(void) rmdir(p);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user