]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
login/user-runtime-dir: free ignored sd_bus_error, avoid triggering assertion 33391/head
authorMike Yuan <me@yhndnzj.com>
Tue, 18 Jun 2024 14:32:14 +0000 (16:32 +0200)
committerMike Yuan <me@yhndnzj.com>
Tue, 18 Jun 2024 21:57:22 +0000 (23:57 +0200)
Fixes #33388

src/login/user-runtime-dir.c

index 967fb5486d703cdb03d26f727908ee66299a71f0..b242f8342936b3b9229574c951b1501575eadf67 100644 (file)
 #include "strv.h"
 #include "user-util.h"
 
-static int acquire_runtime_dir_properties(uint64_t *size, uint64_t *inodes) {
+static int acquire_runtime_dir_properties(uint64_t *ret_size, uint64_t *ret_inodes) {
         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
         _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
+        uint64_t size, inodes;
         int r;
 
+        assert(ret_size);
+        assert(ret_inodes);
+
         r = sd_bus_default_system(&bus);
         if (r < 0)
                 return log_error_errno(r, "Failed to connect to system bus: %m");
 
-        r = bus_get_property_trivial(bus, bus_login_mgr, "RuntimeDirectorySize", &error, 't', size);
+        r = bus_get_property_trivial(bus, bus_login_mgr, "RuntimeDirectorySize", &error, 't', &size);
         if (r < 0) {
                 log_warning_errno(r, "Failed to acquire runtime directory size, ignoring: %s", bus_error_message(&error, r));
-                *size = physical_memory_scale(10U, 100U); /* 10% */
+                sd_bus_error_free(&error);
+
+                size = physical_memory_scale(10U, 100U); /* 10% */
         }
 
-        r = bus_get_property_trivial(bus, bus_login_mgr, "RuntimeDirectoryInodesMax", &error, 't', inodes);
+        r = bus_get_property_trivial(bus, bus_login_mgr, "RuntimeDirectoryInodesMax", &error, 't', &inodes);
         if (r < 0) {
                 log_warning_errno(r, "Failed to acquire number of inodes for runtime directory, ignoring: %s", bus_error_message(&error, r));
-                *inodes = DIV_ROUND_UP(*size, 4096);
+                sd_bus_error_free(&error);
+
+                inodes = DIV_ROUND_UP(size, 4096);
         }
 
+        *ret_size = size;
+        *ret_inodes = inodes;
+
         return 0;
 }