From d610ce4972d23170585648f922457db2b5aa4e83 Mon Sep 17 00:00:00 2001
From: Daniel Carl <danielcarl@gmx.de>
Date: Mon, 29 Jul 2013 19:31:06 +0200
Subject: [PATCH] Fixed wrong free function in history processing.

Also moved freeing to the caller.
---
 src/history.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/history.c b/src/history.c
index 688f9e3..aedf71b 100644
--- a/src/history.c
+++ b/src/history.c
@@ -61,9 +61,12 @@ static void free_history(History *item);
 void history_cleanup(void)
 {
     const char *file;
+    GList *list;
     for (HistoryType i = HISTORY_FIRST; i < HISTORY_LAST; i++) {
         file = get_file_by_type(i);
-        write_to_file(load(file), file);
+        list = load(file);
+        write_to_file(list, file);
+        g_list_free_full(list, (GDestroyNotify)free_history);
     }
 }
 
@@ -209,7 +212,7 @@ gboolean history_fill_completion(GtkListStore *store, HistoryType type, const ch
             }
         }
     }
-    g_list_free_full(src, (GDestroyNotify)g_free);
+    g_list_free_full(src, (GDestroyNotify)free_history);
 
     return found;
 }
@@ -260,6 +263,8 @@ static const char *get_file_by_type(HistoryType type)
 
 /**
  * Loads history items form file but eleminate duplicates in FIFO order.
+ *
+ * Returned list must be freed with (GDestroyNotify) free_history.
  */
 static GList *load(const char *file)
 {
@@ -292,8 +297,6 @@ static void write_to_file(GList *list, const char *file)
         file_lock_set(fileno(f), F_UNLCK);
         fclose(f);
     }
-
-    g_list_free_full(list, (GDestroyNotify)free_history);
 }
 
 static History *line_to_history(const char *line)
-- 
2.20.1