[gnome-settings-daemon/wip/xsettings-manager: 10/16] xsettings: switch manager to GLib memory functions
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon/wip/xsettings-manager: 10/16] xsettings: switch manager to GLib memory functions
- Date: Thu, 8 Mar 2012 14:25:29 +0000 (UTC)
commit 5e878b5360612d7b75d4073babc9303d0cb0d137
Author: Ryan Lortie <desrt desrt ca>
Date: Wed Mar 7 23:24:40 2012 -0500
xsettings: switch manager to GLib memory functions
plugins/xsettings/xsettings-common.c | 39 ++++++++------------------------
plugins/xsettings/xsettings-manager.c | 11 ++++-----
2 files changed, 15 insertions(+), 35 deletions(-)
---
diff --git a/plugins/xsettings/xsettings-common.c b/plugins/xsettings/xsettings-common.c
index 9ac5296..fefb00f 100644
--- a/plugins/xsettings/xsettings-common.c
+++ b/plugins/xsettings/xsettings-common.c
@@ -20,6 +20,9 @@
*
* Author: Owen Taylor, Red Hat, Inc.
*/
+
+#include <glib.h>
+
#include "string.h"
#include "stdlib.h"
@@ -32,18 +35,9 @@ XSettingsSetting *
xsettings_setting_copy (XSettingsSetting *setting)
{
XSettingsSetting *result;
- size_t str_len;
-
- result = malloc (sizeof *result);
- if (!result)
- return NULL;
-
- str_len = strlen (setting->name);
- result->name = malloc (str_len + 1);
- if (!result->name)
- goto err;
- memcpy (result->name, setting->name, str_len + 1);
+ result = g_slice_new (XSettingsSetting);
+ result->name = g_strdup (setting->name);
result->type = setting->type;
@@ -56,25 +50,13 @@ xsettings_setting_copy (XSettingsSetting *setting)
result->data.v_color = setting->data.v_color;
break;
case XSETTINGS_TYPE_STRING:
- str_len = strlen (setting->data.v_string);
- result->data.v_string = malloc (str_len + 1);
- if (!result->data.v_string)
- goto err;
-
- memcpy (result->data.v_string, setting->data.v_string, str_len + 1);
+ result->data.v_string = g_strdup (setting->data.v_string);
break;
}
result->last_change_serial = setting->last_change_serial;
return result;
-
- err:
- if (result->name)
- free (result->name);
- free (result);
-
- return NULL;
}
int
@@ -107,12 +89,11 @@ void
xsettings_setting_free (XSettingsSetting *setting)
{
if (setting->type == XSETTINGS_TYPE_STRING)
- free (setting->data.v_string);
-
- if (setting->name)
- free (setting->name);
+ g_free (setting->data.v_string);
+
+ g_free (setting->name);
- free (setting);
+ g_slice_free (XSettingsSetting, setting);
}
char
diff --git a/plugins/xsettings/xsettings-manager.c b/plugins/xsettings/xsettings-manager.c
index f26a4b3..4cc3818 100644
--- a/plugins/xsettings/xsettings-manager.c
+++ b/plugins/xsettings/xsettings-manager.c
@@ -126,10 +126,8 @@ xsettings_manager_new (Display *display,
XClientMessageEvent xev;
char buffer[256];
-
- manager = malloc (sizeof *manager);
- if (!manager)
- return NULL;
+
+ manager = g_slice_new (XSettingsManager);
manager->display = display;
manager->screen = screen;
@@ -189,9 +187,10 @@ void
xsettings_manager_destroy (XSettingsManager *manager)
{
XDestroyWindow (manager->display, manager->window);
-
+
g_hash_table_unref (manager->settings);
- free (manager);
+
+ g_slice_free (XSettingsManager, manager);
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]