[mutter] xprops: Use g_strdup in class_hint_from_results()
- From: Jonas Ådahl <jadahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] xprops: Use g_strdup in class_hint_from_results()
- Date: Thu, 3 Oct 2019 17:28:13 +0000 (UTC)
commit e15352474865e17de30ffcd3ef505e9f00afd07b
Author: Hans de Goede <hdegoede redhat com>
Date: Mon Sep 9 11:28:00 2019 +0200
xprops: Use g_strdup in class_hint_from_results()
Use g_strdup instead of malloc + strcpy, this also gets rid of a bunch
of error checking which is no longer necessary, also adjust the free
path accordingly.
Note that there was a malloc + XFree mismatch in the removed error-handling.
https://gitlab.gnome.org/GNOME/mutter/merge_requests/786
src/x11/xprops.c | 34 ++++++++--------------------------
1 file changed, 8 insertions(+), 26 deletions(-)
---
diff --git a/src/x11/xprops.c b/src/x11/xprops.c
index d32bb263f..34de50263 100644
--- a/src/x11/xprops.c
+++ b/src/x11/xprops.c
@@ -727,7 +727,7 @@ static gboolean
class_hint_from_results (GetPropertyResults *results,
XClassHint *class_hint)
{
- int len_name, len_class;
+ int len_name;
class_hint->res_class = NULL;
class_hint->res_name = NULL;
@@ -735,31 +735,13 @@ class_hint_from_results (GetPropertyResults *results,
if (!validate_or_free_results (results, 8, XA_STRING, FALSE))
return FALSE;
- len_name = strlen ((char *) results->prop);
- if (! (class_hint->res_name = malloc (len_name+1)))
- {
- g_free (results->prop);
- results->prop = NULL;
- return FALSE;
- }
-
- strcpy (class_hint->res_name, (char *)results->prop);
+ class_hint->res_name = g_strdup ((char *) results->prop);
+ len_name = strlen (class_hint->res_name);
if (len_name == (int) results->n_items)
- len_name--;
-
- len_class = strlen ((char *)results->prop + len_name + 1);
-
- if (! (class_hint->res_class = malloc(len_class+1)))
- {
- XFree(class_hint->res_name);
- class_hint->res_name = NULL;
- g_free (results->prop);
- results->prop = NULL;
- return FALSE;
- }
-
- strcpy (class_hint->res_class, (char *)results->prop + len_name + 1);
+ class_hint->res_class = g_strdup ("");
+ else
+ class_hint->res_class = g_strdup ((char *) results->prop + len_name + 1);
g_free (results->prop);
results->prop = NULL;
@@ -1092,8 +1074,8 @@ free_value (MetaPropValue *value)
g_free (value->v.wm_hints);
break;
case META_PROP_VALUE_CLASS_HINT:
- free (value->v.class_hint.res_class);
- free (value->v.class_hint.res_name);
+ g_free (value->v.class_hint.res_class);
+ g_free (value->v.class_hint.res_name);
break;
case META_PROP_VALUE_SIZE_HINTS:
free (value->v.size_hints.hints);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]