]> granicus.if.org Git - neomutt/commitdiff
encapsulate color_list
authorRichard Russon <rich@flatcap.org>
Fri, 4 Oct 2019 01:19:18 +0000 (02:19 +0100)
committerRichard Russon <rich@flatcap.org>
Tue, 8 Oct 2019 22:45:06 +0000 (23:45 +0100)
color.c

diff --git a/color.c b/color.c
index 817478555c8719aae612d4b20cda9193ea0bd38c..d15b86fd098dc5f019ac5328a521f181d42adbd1 100644 (file)
--- a/color.c
+++ b/color.c
@@ -219,6 +219,27 @@ static void quotes_clear(struct Colors *c)
   c->quotes_used = 0;
 }
 
+/**
+ * color_list_free - Free the list of curses colours
+ * @param ptr Colours
+ */
+static void color_list_free(struct ColorList **ptr)
+{
+  if (!ptr || !*ptr)
+    return;
+
+  struct ColorList *cl = *ptr;
+  struct ColorList *next = NULL;
+
+  while (cl)
+  {
+    next = cl->next;
+    FREE(&cl);
+    cl = next;
+  }
+  *ptr = NULL;
+}
+
 /**
  * color_line_new - Create a new ColorLine
  * @retval ptr Newly allocated ColorLine
@@ -278,6 +299,8 @@ static void colors_clear(struct Colors *c)
 {
   defs_clear(c);
   quotes_clear(c);
+
+  color_list_free(&c->user_colors);
 }
 
 /**
@@ -1283,15 +1306,6 @@ void mutt_colors_free(void)
   color_line_list_clear(&Colors->index_tag_list);
   color_line_list_clear(&Colors->status_list);
 
-  struct ColorList *cl = Colors->user_colors;
-  struct ColorList *next = NULL;
-  while (cl)
-  {
-    next = cl->next;
-    FREE(&cl);
-    cl = next;
-  }
-  Colors->user_colors = NULL;
   colors_clear(Colors);
   defs_free(Colors);
   quotes_free(Colors);