Blame SOURCES/0393-journalctl-unify-how-we-free-boot-id-lists-a-bit.patch

17b0f1
From 76d6062ebf93614a45f1f74be7a93a9a662c5812 Mon Sep 17 00:00:00 2001
17b0f1
From: Lennart Poettering <lennart@poettering.net>
17b0f1
Date: Tue, 19 May 2015 00:35:02 +0200
17b0f1
Subject: [PATCH] journalctl: unify how we free boot id lists a bit
17b0f1
17b0f1
Instead of use LIST_FOREACH_SAFE, just use the same, seperate destructor
17b0f1
everywhere.
17b0f1
17b0f1
Cherry-picked from: 9530e0d023b0e9308f19eadf6e42cdc25bc30793
17b0f1
Related: #1318994
17b0f1
---
17b0f1
 src/journal/journalctl.c | 21 +++++++++++++++------
17b0f1
 1 file changed, 15 insertions(+), 6 deletions(-)
17b0f1
17b0f1
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
17b0f1
index ba9ae05f72..5864ff50a6 100644
17b0f1
--- a/src/journal/journalctl.c
17b0f1
+++ b/src/journal/journalctl.c
17b0f1
@@ -932,6 +932,15 @@ static int add_matches(sd_journal *j, char **args) {
17b0f1
         return 0;
17b0f1
 }
17b0f1
 
17b0f1
+static void boot_id_free_all(BootId *l) {
17b0f1
+
17b0f1
+        while (l) {
17b0f1
+                BootId *i = l;
17b0f1
+                LIST_REMOVE(boot_list, l, i);
17b0f1
+                free(i);
17b0f1
+        }
17b0f1
+}
17b0f1
+
17b0f1
 static int discover_next_boot(
17b0f1
                 sd_journal *j,
17b0f1
                 BootId **boot,
17b0f1
@@ -1009,6 +1018,7 @@ static int discover_next_boot(
17b0f1
 
17b0f1
         *boot = next_boot;
17b0f1
         next_boot = NULL;
17b0f1
+
17b0f1
         return 0;
17b0f1
 }
17b0f1
 
17b0f1
@@ -1080,9 +1090,7 @@ static int get_boots(
17b0f1
 
17b0f1
                 r = discover_next_boot(j, &current, advance_older, !query_ref_boot);
17b0f1
                 if (r < 0) {
17b0f1
-                        BootId *id, *id_next;
17b0f1
-                        LIST_FOREACH_SAFE(boot_list, id, id_next, head)
17b0f1
-                                free(id);
17b0f1
+                        boot_id_free_all(head);
17b0f1
                         return r;
17b0f1
                 }
17b0f1
 
17b0f1
@@ -1118,7 +1126,7 @@ finish:
17b0f1
 
17b0f1
 static int list_boots(sd_journal *j) {
17b0f1
         int w, i, count;
17b0f1
-        BootId *id, *id_next, *all_ids;
17b0f1
+        BootId *id, *all_ids;
17b0f1
 
17b0f1
         assert(j);
17b0f1
 
17b0f1
@@ -1132,7 +1140,7 @@ static int list_boots(sd_journal *j) {
17b0f1
         w = DECIMAL_STR_WIDTH(count - 1) + 1;
17b0f1
 
17b0f1
         i = 0;
17b0f1
-        LIST_FOREACH_SAFE(boot_list, id, id_next, all_ids) {
17b0f1
+        LIST_FOREACH(boot_list, id, all_ids) {
17b0f1
                 char a[FORMAT_TIMESTAMP_MAX], b[FORMAT_TIMESTAMP_MAX];
17b0f1
 
17b0f1
                 printf("% *i " SD_ID128_FORMAT_STR " %s—%s\n",
17b0f1
@@ -1141,9 +1149,10 @@ static int list_boots(sd_journal *j) {
17b0f1
                        format_timestamp_maybe_utc(a, sizeof(a), id->first),
17b0f1
                        format_timestamp_maybe_utc(b, sizeof(b), id->last));
17b0f1
                 i++;
17b0f1
-                free(id);
17b0f1
         }
17b0f1
 
17b0f1
+        boot_id_free_all(all_ids);
17b0f1
+
17b0f1
         return 0;
17b0f1
 }
17b0f1