core/umount: use _cleanup_ in one more place
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 27 Nov 2017 16:13:04 +0000 (16:13 +0000)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 28 Nov 2017 08:25:38 +0000 (09:25 +0100)
src/core/umount.c

index cd195e1..cd58a9c 100644 (file)
@@ -159,7 +159,7 @@ static int swap_list_get(MountPoint **head) {
 
         for (i = 2;; i++) {
                 MountPoint *swap;
-                char *dev = NULL, *d;
+                _cleanup_free_ char *dev = NULL, *d = NULL;
                 int k;
 
                 k = fscanf(proc_swaps,
@@ -175,27 +175,21 @@ static int swap_list_get(MountPoint **head) {
                                 break;
 
                         log_warning("Failed to parse /proc/swaps:%u.", i);
-                        free(dev);
                         continue;
                 }
 
-                if (endswith(dev, " (deleted)")) {
-                        free(dev);
+                if (endswith(dev, " (deleted)"))
                         continue;
-                }
 
                 r = cunescape(dev, UNESCAPE_RELAX, &d);
-                free(dev);
                 if (r < 0)
                         return r;
 
                 swap = new0(MountPoint, 1);
-                if (!swap) {
-                        free(d);
+                if (!swap)
                         return -ENOMEM;
-                }
 
-                swap->path = d;
+                free_and_replace(swap->path, d);
                 LIST_PREPEND(mount_point, *head, swap);
         }