[PATCH 1/5] tests: allocate memory in a coherent fashion

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

 



Do not free memory allocated with C functions (like calloc) using g_free;
although this is possible with default Glib allocator this is not safe.
Also use consistent allocation functions. All other spice-server code
does not use Glib allocations so for coherence do not use them for
watches.

Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
---
 server/tests/basic_event_loop.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/server/tests/basic_event_loop.c b/server/tests/basic_event_loop.c
index 85b4da4..c9c2637 100644
--- a/server/tests/basic_event_loop.c
+++ b/server/tests/basic_event_loop.c
@@ -25,6 +25,7 @@
 
 #include "spice/macros.h"
 #include "common/ring.h"
+#include "common/mem.h"
 #include "test_util.h"
 #include "basic_event_loop.h"
 
@@ -47,7 +48,7 @@ struct SpiceTimer {
 
 static SpiceTimer* timer_add(SpiceTimerFunc func, void *opaque)
 {
-    SpiceTimer *timer = calloc(sizeof(SpiceTimer), 1);
+    SpiceTimer *timer = spice_malloc0(sizeof(SpiceTimer));
 
     timer->func = func;
     timer->opaque = opaque;
@@ -85,7 +86,7 @@ static void timer_start(SpiceTimer *timer, uint32_t ms)
 static void timer_remove(SpiceTimer *timer)
 {
     timer_cancel(timer);
-    g_free(timer);
+    free(timer);
 }
 
 struct SpiceWatch {
@@ -135,7 +136,7 @@ static SpiceWatch *watch_add(int fd, int event_mask, SpiceWatchFunc func, void *
     SpiceWatch *watch;
     GIOCondition condition = spice_event_to_condition(event_mask);
 
-    watch = g_new(SpiceWatch, 1);
+    watch = spice_malloc0(sizeof(SpiceWatch));
     watch->channel = g_io_channel_unix_new(fd);
     watch->source_id = g_io_add_watch(watch->channel, condition, watch_func, watch);
     watch->func = func;
@@ -157,7 +158,7 @@ static void watch_remove(SpiceWatch *watch)
 {
     g_source_remove(watch->source_id);
     g_io_channel_unref(watch->channel);
-    g_free(watch);
+    free(watch);
 }
 
 static void channel_event(int event, SpiceChannelEventInfo *info)
-- 
2.4.3

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]