]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/login/logind-inhibit.c
tree-wide: use unlink_and_freep() moreover
[thirdparty/systemd.git] / src / login / logind-inhibit.c
index 95b11ed9e731796dc5c792be18762f59f6546b4a..8735538d209ce4f0747327bb86e8f7a26e58700d 100644 (file)
@@ -14,6 +14,7 @@
 #include "fd-util.h"
 #include "fileio.h"
 #include "format-util.h"
+#include "fs-util.h"
 #include "io-util.h"
 #include "logind-dbus.h"
 #include "logind-inhibit.h"
@@ -83,7 +84,7 @@ Inhibitor* inhibitor_free(Inhibitor *i) {
 }
 
 static int inhibitor_save(Inhibitor *i) {
-        _cleanup_free_ char *temp_path = NULL;
+        _cleanup_(unlink_and_freep) char *temp_path = NULL;
         _cleanup_fclose_ FILE *f = NULL;
         int r;
 
@@ -146,14 +147,12 @@ static int inhibitor_save(Inhibitor *i) {
                 goto fail;
         }
 
+        temp_path = mfree(temp_path);
         return 0;
 
 fail:
         (void) unlink(i->state_file);
 
-        if (temp_path)
-                (void) unlink(temp_path);
-
         return log_error_errno(r, "Failed to save inhibit data %s: %m", i->state_file);
 }