]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal: Use cleanup_free
authorSusant Sahani <ssahani@vmware.com>
Wed, 20 Jan 2021 11:46:42 +0000 (12:46 +0100)
committerSusant Sahani <ssahani@vmware.com>
Wed, 20 Jan 2021 14:08:59 +0000 (15:08 +0100)
src/libsystemd/sd-journal/sd-journal.c

index 46b1cba1452d0991e4c53cc3cde35eb44f723ff3..ff26f5d7e7929bad87ff19209253885f54c4fcb4 100644 (file)
@@ -63,7 +63,7 @@ static bool journal_pid_changed(sd_journal *j) {
 }
 
 static int journal_put_error(sd_journal *j, int r, const char *path) {
-        char *copy;
+        _cleanup_free_ char *copy = NULL;
         int k;
 
         /* Memorize an error we encountered, and store which
@@ -84,19 +84,17 @@ static int journal_put_error(sd_journal *j, int r, const char *path) {
                 copy = strdup(path);
                 if (!copy)
                         return -ENOMEM;
-        } else
-                copy = NULL;
+        }
 
         k = hashmap_ensure_put(&j->errors, NULL, INT_TO_PTR(r), copy);
         if (k < 0) {
-                free(copy);
-
                 if (k == -EEXIST)
                         return 0;
 
                 return k;
         }
 
+        TAKE_PTR(copy);
         return 0;
 }