summaryrefslogtreecommitdiff
path: root/src/xsettings.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@penguin.cs.ucla.edu>2014-02-28 13:45:34 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2014-02-28 13:45:34 -0800
commit8268febfe0c336ff47a61d0d416fd4bebf61a993 (patch)
tree4a1590e6aff922e69646cc35347192ea507b1c7a /src/xsettings.c
parentb70257b07ea6053bce27b20ad0bda50f547bd393 (diff)
downloademacs-8268febfe0c336ff47a61d0d416fd4bebf61a993.tar.gz
Fix a few crashes and leaks when cloning C strings.
* alloc.c, lisp.h (dupstring): New function. * gtkutil.c (xg_get_font): * term.c (tty_default_color_capabilities): * xsettings.c (store_monospaced_changed) (store_font_name_changed, parse_settings) (read_and_apply_settings, init_gsettings, init_gconf): Use it. This avoids some unlikely crashes due to accessing freed storage, and avoids some minor memory leaks in the more-typical case.
Diffstat (limited to 'src/xsettings.c')
-rw-r--r--src/xsettings.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/src/xsettings.c b/src/xsettings.c
index 458c3d45e9a..844da19f638 100644
--- a/src/xsettings.c
+++ b/src/xsettings.c
@@ -91,8 +91,7 @@ store_monospaced_changed (const char *newfont)
if (current_mono_font != NULL && strcmp (newfont, current_mono_font) == 0)
return; /* No change. */
- xfree (current_mono_font);
- current_mono_font = xstrdup (newfont);
+ dupstring (&current_mono_font, newfont);
if (dpyinfo_valid (first_dpyinfo) && use_system_font)
{
@@ -111,8 +110,7 @@ store_font_name_changed (const char *newfont)
if (current_font != NULL && strcmp (newfont, current_font) == 0)
return; /* No change. */
- xfree (current_font);
- current_font = xstrdup (newfont);
+ dupstring (&current_font, newfont);
if (dpyinfo_valid (first_dpyinfo))
{
@@ -492,13 +490,13 @@ parse_settings (unsigned char *prop,
++settings_seen;
if (strcmp (name, XSETTINGS_TOOL_BAR_STYLE) == 0)
{
- settings->tb_style = xstrdup (sval);
+ dupstring (&settings->tb_style, sval);
settings->seen |= SEEN_TB_STYLE;
}
#ifdef HAVE_XFT
else if (strcmp (name, XSETTINGS_FONT_NAME) == 0)
{
- settings->font = xstrdup (sval);
+ dupstring (&settings->font, sval);
settings->seen |= SEEN_FONT;
}
else if (strcmp (name, "Xft/Antialias") == 0)
@@ -742,10 +740,7 @@ read_and_apply_settings (struct x_display_info *dpyinfo, int send_event_p)
if (send_event_p)
store_font_name_changed (settings.font);
else
- {
- xfree (current_font);
- current_font = xstrdup (settings.font);
- }
+ dupstring (&current_font, settings.font);
xfree (settings.font);
}
#endif
@@ -835,7 +830,7 @@ init_gsettings (void)
{
g_variant_ref_sink (val);
if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING))
- current_mono_font = xstrdup (g_variant_get_string (val, NULL));
+ dupstring (&current_mono_font, g_variant_get_string (val, NULL));
g_variant_unref (val);
}
@@ -844,7 +839,7 @@ init_gsettings (void)
{
g_variant_ref_sink (val);
if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING))
- current_font = xstrdup (g_variant_get_string (val, NULL));
+ dupstring (&current_font, g_variant_get_string (val, NULL));
g_variant_unref (val);
}
#endif /* HAVE_XFT */
@@ -886,13 +881,13 @@ init_gconf (void)
s = gconf_client_get_string (gconf_client, GCONF_MONO_FONT, NULL);
if (s)
{
- current_mono_font = xstrdup (s);
+ dupstring (&current_mono_font, s);
g_free (s);
}
s = gconf_client_get_string (gconf_client, GCONF_FONT_NAME, NULL);
if (s)
{
- current_font = xstrdup (s);
+ dupstring (&current_font, s);
g_free (s);
}
gconf_client_add_dir (gconf_client,