mirror of
https://github.com/irssi/irssi.git
synced 2024-11-03 04:27:19 -05:00
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
This commit is contained in:
parent
418136656d
commit
49c8ba4058
@ -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);
|
||||
/* 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);
|
||||
|
||||
recode_fallback = settings_get_str("recode_fallback");
|
||||
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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user