]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sleep: fix memleak 26159/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 23 Jan 2023 14:50:36 +0000 (15:50 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 23 Jan 2023 21:06:05 +0000 (22:06 +0100)
Those hashmaps are created anew in each iteration of the loop. The
leak wasn't really a problem, because the loop is bounded and the
hashmaps were not huge, but it's nicer to be correct.

src/sleep/sleep.c

index de5b9ae19227f3a8ed661d4f59790a3a099ecaa7..c2c8c779ad8bea209531608363fdfea8dafb8573 100644 (file)
@@ -267,12 +267,12 @@ static int execute(
 }
 
 static int custom_timer_suspend(const SleepConfig *sleep_config) {
-        _cleanup_hashmap_free_ Hashmap *last_capacity = NULL, *current_capacity = NULL;
         int r;
 
         assert(sleep_config);
 
         while (battery_is_low() == 0) {
+                _cleanup_hashmap_free_ Hashmap *last_capacity = NULL, *current_capacity = NULL;
                 _cleanup_close_ int tfd = -EBADF;
                 struct itimerspec ts = {};
                 usec_t suspend_interval = sleep_config->hibernate_delay_sec, before_timestamp = 0, after_timestamp = 0, total_suspend_interval;