[Libosinfo] [PATCH 13/14] osinfo: Add GDestroyNotify callback to g_task_return_pointer calls

Christophe Fergeau cfergeau at redhat.com
Wed Jun 8 10:01:17 UTC 2016


The GDestroyNotify callback passed to g_task_return_pointer() is used to
free the associated pointer in case g_task_propagate_pointer() is not
called (error cases, _finish() never called, ...).

When the GTask owns the pointer it's passed through
g_task_return_pointer() (for example the _finish() function is (transfer
full) and only calls g_task_propagate_pointer()), we need to set a
GDestroyNotify when calling g_task_return_pointer() or we may have leaks
in corner cases.
---
 osinfo/osinfo_install_script.c | 4 ++--
 osinfo/osinfo_media.c          | 2 +-
 osinfo/osinfo_tree.c           | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/osinfo/osinfo_install_script.c b/osinfo/osinfo_install_script.c
index 2465771..ebe1887 100644
--- a/osinfo/osinfo_install_script.c
+++ b/osinfo/osinfo_install_script.c
@@ -901,7 +901,7 @@ static void osinfo_install_script_template_loaded(GObject *src,
         goto cleanup;
     }
 
-    g_task_return_pointer(data->res, output, NULL);
+    g_task_return_pointer(data->res, output, g_free);
 
  cleanup:
     g_free(input);
@@ -955,7 +955,7 @@ static void osinfo_install_script_generate_async_common(OsinfoInstallScript *scr
             osinfo_install_script_generate_data_free(data);
             return;
         }
-        g_task_return_pointer(data->res, output, NULL);
+        g_task_return_pointer(data->res, output, g_free);
         osinfo_install_script_generate_data_free(data);
     } else {
         GFile *file = g_file_new_for_uri(templateUri);
diff --git a/osinfo/osinfo_media.c b/osinfo/osinfo_media.c
index f7bf120..b45f4f4 100644
--- a/osinfo/osinfo_media.c
+++ b/osinfo/osinfo_media.c
@@ -758,7 +758,7 @@ EXIT:
     if (error != NULL)
         g_task_return_error(data->res, error);
     else
-        g_task_return_pointer(data->res, media, NULL);
+        g_task_return_pointer(data->res, media, g_object_unref);
 
     g_object_unref(stream);
     create_from_location_async_data_free(data);
diff --git a/osinfo/osinfo_tree.c b/osinfo/osinfo_tree.c
index 6fc62f7..565ccfe 100644
--- a/osinfo/osinfo_tree.c
+++ b/osinfo/osinfo_tree.c
@@ -614,7 +614,7 @@ static void on_location_read(GObject *source,
         goto cleanup;
     }
 
-    g_task_return_pointer(data->res, ret, NULL);
+    g_task_return_pointer(data->res, ret, g_object_unref);
 
  cleanup:
     create_from_location_async_data_free(data);
-- 
2.7.4




More information about the Libosinfo mailing list