[dconf] Use normal slice allocation for OutstandingWatch



commit 08529e13f62a33e7ed94a2319c9f35feea95fa6a
Author: Ryan Lortie <desrt desrt ca>
Date:   Fri Jan 14 11:33:26 2011 -0500

    Use normal slice allocation for OutstandingWatch
    
    The fact that the last commit broke the old code is proof that it was
    far too fragile.  Change it to use more common idioms (at the cost of an
    extremely marginal increase in memory consumption).

 gsettings/dconfsettingsbackend.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
---
diff --git a/gsettings/dconfsettingsbackend.c b/gsettings/dconfsettingsbackend.c
index 0cab0d3..bbd3c32 100644
--- a/gsettings/dconfsettingsbackend.c
+++ b/gsettings/dconfsettingsbackend.c
@@ -478,7 +478,7 @@ typedef struct
 {
   DConfSettingsBackend *dcsb;
   guint64 state;
-  gchar name[1];
+  gchar *name;
   gint outstanding;
 } OutstandingWatch;
 
@@ -490,11 +490,11 @@ outstanding_watch_new (DConfSettingsBackend *dcsb,
   gsize length;
 
   length = strlen (name);
-  watch = g_malloc (G_STRUCT_OFFSET (OutstandingWatch, name) + length + 1);
+  watch = g_slice_new (OutstandingWatch);
   watch->dcsb = g_object_ref (dcsb);
   watch->state = dconf_engine_get_state (dcsb->engine);
   watch->outstanding = 0;
-  strcpy (watch->name, name);
+  watch->name = g_strdup (name);
 
   return watch;
 }
@@ -505,7 +505,9 @@ outstanding_watch_free (OutstandingWatch *watch)
   if (--watch->outstanding == 0)
     {
       g_object_unref (watch->dcsb);
-      g_free (watch);
+      g_free (watch->name);
+
+      g_slice_free (OutstandingWatch, watch);
     }
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]