summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValentin Batz <senneth@irssi.org>2005-03-06 21:49:57 +0000
committervb <vb@dbcabf3a-b0e7-0310-adc4-f8d773084564>2005-03-06 21:49:57 +0000
commit49c8ba40584ef17cd089d3bb3d6dd44f7c059828 (patch)
tree78325ce8a4c655aa744b472fc6f7485876b50db5
parent418136656df8a2a002a74bd3f665717abfb11d65 (diff)
downloadirssi-49c8ba40584ef17cd089d3bb3d6dd44f7c059828.zip
Fixed memleak when preserving valid charsets in read_settings in fe-recode.c (Bug 210)
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@3718 dbcabf3a-b0e7-0310-adc4-f8d773084564
-rw-r--r--src/fe-common/core/fe-recode.c61
1 files changed, 35 insertions, 26 deletions
diff --git a/src/fe-common/core/fe-recode.c b/src/fe-common/core/fe-recode.c
index f68dff17..afdfa431 100644
--- a/src/fe-common/core/fe-recode.c
+++ b/src/fe-common/core/fe-recode.c
@@ -39,9 +39,9 @@ for ((var) = (head); \
(var) = g_slist_next((var)))
#ifdef HAVE_GLIB2
-const char *recode_fallback = NULL;
-const char *recode_out_default = NULL;
-const char *term_charset = NULL;
+char *recode_fallback = NULL;
+char *recode_out_default = NULL;
+char *term_charset = NULL;
static const char *fe_recode_get_target (WI_ITEM_REC *witem)
{
@@ -151,41 +151,51 @@ static void fe_recode_remove_cmd (const char *data, SERVER_REC *server, WI_ITEM_
static void read_settings(void)
{
- const char *old_term_charset = g_strdup (term_charset);
- const char *old_recode_fallback = g_strdup (recode_fallback);
- const char *old_recode_out_default = g_strdup (recode_out_default);
-
- recode_fallback = settings_get_str("recode_fallback");
+ /* preserve the valid values */
+ const char *old_term_charset = g_strdup(term_charset);
+ const char *old_recode_fallback = g_strdup(recode_fallback);
+ const char *old_recode_out_default = g_strdup(recode_out_default);
+
+ if (recode_fallback)
+ g_free(term_charset);
+ recode_fallback = g_strdup(settings_get_str("recode_fallback"));
if (!is_valid_charset(recode_fallback)) {
signal_emit("error command", 2, GINT_TO_POINTER(CMDERR_INVALID_CHARSET), recode_fallback);
- settings_set_str("recode_fallback", old_recode_fallback != NULL ? old_recode_fallback : "ISO8859-1");
+ g_free(recode_fallback);
+ recode_fallback = is_valid_charset(old_recode_fallback) ? g_strdup(old_recode_fallback) : "ISO8859-1";
+ settings_set_str("recode_fallback", recode_fallback);
}
- recode_fallback = g_strdup(settings_get_str("recode_fallback"));
-
- term_charset = settings_get_str("term_charset");
+
+ if (term_charset)
+ g_free(term_charset);
+ term_charset = g_strdup(settings_get_str("term_charset"));
if (!is_valid_charset(term_charset)) {
+ g_free(term_charset);
#if defined (HAVE_NL_LANGINFO) && defined(CODESET)
- settings_set_str("term_charset", is_valid_charset(old_term_charset) ?
- old_term_charset : *nl_langinfo(CODESET) != '\0' ?
- nl_langinfo(CODESET) : "ISO8859-1");
+ term_charset = is_valid_charset(old_term_charset) ? g_strdup(old_term_charset) :
+ *nl_langinfo(CODESET) != '\0' ? g_strdup(nl_langinfo(CODESET)) :
+ "ISO8859-1";
#else
- settings_set_str("term_charset", is_valid_charset(old_term_charset) ? old_term_charset : "ISO8859-1");
+ term_charset = is_valid_charset(old_term_charset) ? g_strdup(old_term_charset) : "ISO8859-1";
#endif
+ settings_set_str("term_charset", term_charset);
/* FIXME: move the check of term_charset into fe-text/term.c
it breaks the proper term_input_type
setup and reemitting of the signal is kludgy */
- if (g_strcasecmp(term_charset, old_term_charset) != 0);
+ if (g_strcasecmp(term_charset, old_term_charset) != 0)
signal_emit("setup changed", 0);
}
- term_charset = g_strdup(settings_get_str("term_charset"));
-
- recode_out_default = settings_get_str("recode_out_default_charset");
- if (recode_out_default != NULL && *recode_out_default != '\0')
- if( !is_valid_charset(recode_out_default)) {
- signal_emit("error command", 2, GINT_TO_POINTER(CMDERR_INVALID_CHARSET), recode_out_default);
- settings_set_str("recode_out_default_charset", old_recode_out_default);
- }
+
+ if (recode_out_default)
+ g_free(recode_out_default);
recode_out_default = g_strdup(settings_get_str("recode_out_default_charset"));
+ if (recode_out_default != NULL && *recode_out_default != '\0' &&
+ !is_valid_charset(recode_out_default)) {
+ signal_emit("error command", 2, GINT_TO_POINTER(CMDERR_INVALID_CHARSET), recode_out_default);
+ g_free(recode_out_default);
+ recode_out_default = is_valid_charset(old_recode_out_default) ? g_strdup(old_recode_out_default) : NULL;
+ settings_set_str("recode_out_default_charset", recode_out_default);
+ }
}
static void message_own_public(const SERVER_REC *server, const char *msg,
@@ -255,4 +265,3 @@ void fe_recode_deinit (void)
signal_remove("message irc own_notice", (SIGNAL_FUNC) message_irc_own_notice);
#endif
}
-