From d668d15081f3d38d618457cb9016100acc6877dc Mon Sep 17 00:00:00 2001
From: James Booth <boothj5@gmail.com>
Date: Wed, 18 Jun 2014 21:36:09 +0100
Subject: [PATCH] Free aliases on cmd_init

---
 src/command/command.c    |  1 +
 src/config/preferences.c | 12 ++++++++----
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/command/command.c b/src/command/command.c
index 6882109f..20e29795 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -971,6 +971,7 @@ cmd_init(void)
         g_string_free(ac_alias, TRUE);
         curr = g_list_next(curr);
     }
+    prefs_free_aliases(aliases);
 
     prefs_ac = autocomplete_new();
     autocomplete_add(prefs_ac, "ui");
diff --git a/src/config/preferences.c b/src/config/preferences.c
index 49203bfb..b187bc32 100644
--- a/src/config/preferences.c
+++ b/src/config/preferences.c
@@ -348,11 +348,15 @@ prefs_get_aliases(void)
             char *name = keys[i];
             char *value = g_key_file_get_string(prefs, PREF_GROUP_ALIAS, name, NULL);
 
-            ProfAlias *alias = malloc(sizeof(struct prof_alias_t));
-            alias->name = strdup(name);
-            alias->value = strdup(value);
+            if (value != NULL) {
+                ProfAlias *alias = malloc(sizeof(struct prof_alias_t));
+                alias->name = strdup(name);
+                alias->value = strdup(value);
 
-            result = g_list_insert_sorted(result, alias, (GCompareFunc)_alias_cmp);
+                free(value);
+
+                result = g_list_insert_sorted(result, alias, (GCompareFunc)_alias_cmp);
+            }
         }
 
         g_strfreev(keys);