Plug a memory leak in g_simple_async_result_set_op_res_gpointer
authorMatthias Clasen <mclasen@redhat.com>
Sun, 3 May 2009 02:59:02 +0000 (22:59 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 3 May 2009 02:59:02 +0000 (22:59 -0400)
Fixes bug 579272.

gio/gsimpleasyncresult.c

index d5c3e7bd142753fa7bc281bab92ce3fbbd6972da..6b73358e5a7b41812adc701b381b286307493531 100644 (file)
@@ -144,6 +144,15 @@ G_DEFINE_TYPE_WITH_CODE (GSimpleAsyncResult, g_simple_async_result, G_TYPE_OBJEC
                         G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_RESULT,
                                                g_simple_async_result_async_result_iface_init))
 
+static void
+clear_op_res (GSimpleAsyncResult *simple)
+{
+  if (simple->destroy_op_res)
+    simple->destroy_op_res (simple->op_res.v_pointer);
+  simple->destroy_op_res = NULL;
+  simple->op_res.v_ssize = 0;
+}
+
 static void
 g_simple_async_result_finalize (GObject *object)
 {
@@ -154,8 +163,7 @@ g_simple_async_result_finalize (GObject *object)
   if (simple->source_object)
     g_object_unref (simple->source_object);
 
-  if (simple->destroy_op_res)
-    simple->destroy_op_res (simple->op_res.v_pointer);
+  clear_op_res (simple);
 
   if (simple->error)
     g_error_free (simple->error);
@@ -375,6 +383,7 @@ g_simple_async_result_set_op_res_gpointer (GSimpleAsyncResult *simple,
 {
   g_return_if_fail (G_IS_SIMPLE_ASYNC_RESULT (simple));
 
+  clear_op_res (simple);
   simple->op_res.v_pointer = op_res;
   simple->destroy_op_res = destroy_op_res;
 }
@@ -407,6 +416,7 @@ g_simple_async_result_set_op_res_gssize (GSimpleAsyncResult *simple,
                                          gssize              op_res)
 {
   g_return_if_fail (G_IS_SIMPLE_ASYNC_RESULT (simple));
+  clear_op_res (simple);
   simple->op_res.v_ssize = op_res;
 }
 
@@ -437,6 +447,7 @@ g_simple_async_result_set_op_res_gboolean (GSimpleAsyncResult *simple,
                                            gboolean            op_res)
 {
   g_return_if_fail (G_IS_SIMPLE_ASYNC_RESULT (simple));
+  clear_op_res (simple);
   simple->op_res.v_boolean = !!op_res;
 }