]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: cleanup unit's dropin directories from global cache
authorMichal Sekletar <msekleta@redhat.com>
Wed, 25 Feb 2026 18:45:55 +0000 (19:45 +0100)
committerMike Yuan <me@yhndnzj.com>
Thu, 5 Mar 2026 15:50:25 +0000 (16:50 +0100)
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 fce94c5c563b8f6ede2b8f7f283d2d2faff4e062.

src/core/unit.c

index bb3430186cab0ed998bfd43b1d3e8d0a7bde2b65..ab0db25687826388d8e133ddbb6af1465dbcce48 100644 (file)
@@ -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);
         }