summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2011-01-02 16:34:47 +0100
committerSebastien Helleu <flashcode@flashtux.org>2011-01-02 16:34:47 +0100
commitce1aac77e0a36e6158eee803080d8f84a7d64a26 (patch)
treea96a1be9ad3a917b2232cb1293fbc12f97010693 /src/gui
parent44e16c05110a19fd8c622d3aeb46179d05d8ec69 (diff)
downloadweechat-ce1aac77e0a36e6158eee803080d8f84a7d64a26.zip
Free color palette structures when exiting WeeChat
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/curses/gui-curses-color.c3
-rw-r--r--src/gui/gui-color.c49
-rw-r--r--src/gui/gui-color.h3
3 files changed, 48 insertions, 7 deletions
diff --git a/src/gui/curses/gui-curses-color.c b/src/gui/curses/gui-curses-color.c
index 5ca996e3f..7f8b6c22c 100644
--- a/src/gui/curses/gui-curses-color.c
+++ b/src/gui/curses/gui-curses-color.c
@@ -893,7 +893,7 @@ gui_color_palette_build_aliases ()
if (!gui_color_hash_palette_alias || !gui_color_list_with_alias
|| !gui_color_hash_palette_color)
{
- gui_color_palette_alloc ();
+ gui_color_palette_alloc_structs ();
}
hashtable_remove_all (gui_color_hash_palette_alias);
@@ -1050,4 +1050,5 @@ gui_color_end ()
{
gui_color_free (gui_color[i]);
}
+ gui_color_palette_free_structs ();
}
diff --git a/src/gui/gui-color.c b/src/gui/gui-color.c
index d7088a987..46d2c302b 100644
--- a/src/gui/gui-color.c
+++ b/src/gui/gui-color.c
@@ -480,11 +480,32 @@ gui_color_free (struct t_gui_color *color)
}
/*
- * gui_color_palette_alloc: allocate hashtables and lists for palette
+ * gui_color_palette_free_value_cb: callback called to free value in hashtable
+ * when item in hashtable is removed
*/
void
-gui_color_palette_alloc ()
+gui_color_palette_free_value_cb (struct t_hashtable *hashtable,
+ const void *key, void *value)
+{
+ struct t_gui_color_palette *color_palette;
+
+ /* make C compiler happy */
+ (void) hashtable;
+ (void) key;
+
+ color_palette = (struct t_gui_color_palette *)value;
+
+ if (color_palette)
+ gui_color_palette_free (color_palette);
+}
+
+/*
+ * gui_color_palette_alloc_structs: allocate hashtables and lists for palette
+ */
+
+void
+gui_color_palette_alloc_structs ()
{
if (!gui_color_hash_palette_color)
{
@@ -493,6 +514,9 @@ gui_color_palette_alloc ()
WEECHAT_HASHTABLE_POINTER,
NULL,
NULL);
+ hashtable_set_pointer (gui_color_hash_palette_color,
+ "callback_free_value",
+ &gui_color_palette_free_value_cb);
}
if (!gui_color_hash_palette_alias)
{
@@ -553,7 +577,7 @@ gui_color_palette_add (int number, const char *value)
struct t_gui_color_palette *new_color_palette, *ptr_color_palette;
char str_number[64];
- gui_color_palette_alloc ();
+ gui_color_palette_alloc_structs ();
new_color_palette = gui_color_palette_new (number, value);
if (!new_color_palette)
@@ -585,7 +609,7 @@ gui_color_palette_remove (int number)
struct t_gui_color_palette *ptr_color_palette;
char str_number[64];
- gui_color_palette_alloc ();
+ gui_color_palette_alloc_structs ();
snprintf (str_number, sizeof (str_number), "%d", number);
ptr_color_palette = hashtable_get (gui_color_hash_palette_color,
@@ -613,7 +637,7 @@ gui_color_palette_change (int number, const char *value)
struct t_gui_color_palette *ptr_color_palette;
char str_number[64];
- gui_color_palette_alloc ();
+ gui_color_palette_alloc_structs ();
snprintf (str_number, sizeof (str_number), "%d", number);
ptr_color_palette = hashtable_get (gui_color_hash_palette_color,
@@ -625,3 +649,18 @@ gui_color_palette_change (int number, const char *value)
gui_color_palette_add (number, value);
}
}
+
+/*
+ * gui_color_palette_free_structs: free hashtables and lists for palette
+ */
+
+void
+gui_color_palette_free_structs ()
+{
+ if (gui_color_hash_palette_color)
+ hashtable_free (gui_color_hash_palette_color);
+ if (gui_color_hash_palette_alias)
+ hashtable_free (gui_color_hash_palette_alias);
+ if (gui_color_list_with_alias)
+ weelist_free (gui_color_list_with_alias);
+}
diff --git a/src/gui/gui-color.h b/src/gui/gui-color.h
index d279cebd9..e756ac84b 100644
--- a/src/gui/gui-color.h
+++ b/src/gui/gui-color.h
@@ -153,12 +153,13 @@ extern const char *gui_color_get_custom (const char *color_name);
extern char *gui_color_decode (const char *string, const char *replacement);
extern char *gui_color_string_replace_colors (const char *string);
extern void gui_color_free (struct t_gui_color *color);
-extern void gui_color_palette_alloc ();
+extern void gui_color_palette_alloc_structs ();
extern int gui_color_palette_get_alias (const char *alias);
extern struct t_gui_color_palette *gui_color_palette_get (int number);
extern void gui_color_palette_add (int number, const char *value);
extern void gui_color_palette_remove (int number);
extern void gui_color_palette_change (int number, const char *value);
+extern void gui_color_palette_free_structs ();
/* color functions (GUI dependent) */