[libpeas] Plug a test memory leak



commit d7144d81aabcf49de1fa10dac712c0580def2647
Author: Garrett Regier <garrettregier gmail com>
Date:   Mon Sep 8 22:57:55 2014 -0700

    Plug a test memory leak
    
    The bindings cannot return a constant string
    from an interface. Instead they dup the string
    and leak it.

 .../libpeas/introspection/introspection-callable.c |    4 ++--
 .../libpeas/introspection/introspection-callable.h |    4 ++--
 .../plugins/extension-c/extension-c-plugin.c       |    4 ++--
 tests/libpeas/testing/testing-extension.c          |    4 +++-
 4 files changed, 9 insertions(+), 7 deletions(-)
---
diff --git a/tests/libpeas/introspection/introspection-callable.c 
b/tests/libpeas/introspection/introspection-callable.c
index 793bf32..cb622c9 100644
--- a/tests/libpeas/introspection/introspection-callable.c
+++ b/tests/libpeas/introspection/introspection-callable.c
@@ -36,9 +36,9 @@ introspection_callable_default_init (IntrospectionCallableInterface *iface)
  * introspection_callable_call_with_return:
  * @callable:
  *
- * Returns: (transfer none):
+ * Returns: (transfer full):
  */
-const gchar *
+gchar *
 introspection_callable_call_with_return (IntrospectionCallable *callable)
 {
   IntrospectionCallableInterface *iface;
diff --git a/tests/libpeas/introspection/introspection-callable.h 
b/tests/libpeas/introspection/introspection-callable.h
index 12917bd..dc844ef 100644
--- a/tests/libpeas/introspection/introspection-callable.h
+++ b/tests/libpeas/introspection/introspection-callable.h
@@ -42,7 +42,7 @@ struct _IntrospectionCallableInterface {
   GTypeInterface g_iface;
 
   /* Virtual public methods */
-  const gchar *(*call_with_return) (IntrospectionCallable *callable);
+  gchar       *(*call_with_return) (IntrospectionCallable *callable);
   void         (*call_no_args)     (IntrospectionCallable *callable);
   void         (*call_single_arg)  (IntrospectionCallable *callable,
                                     gboolean              *called);
@@ -60,7 +60,7 @@ struct _IntrospectionCallableInterface {
  */
 GType        introspection_callable_get_type         (void) G_GNUC_CONST;
 
-const gchar *introspection_callable_call_with_return (IntrospectionCallable *callable);
+gchar       *introspection_callable_call_with_return (IntrospectionCallable *callable);
 
 void         introspection_callable_call_no_args     (IntrospectionCallable *callable);
 void         introspection_callable_call_single_arg  (IntrospectionCallable *callable,
diff --git a/tests/libpeas/plugins/extension-c/extension-c-plugin.c 
b/tests/libpeas/plugins/extension-c/extension-c-plugin.c
index d40e6e1..1b70fa5 100644
--- a/tests/libpeas/plugins/extension-c/extension-c-plugin.c
+++ b/tests/libpeas/plugins/extension-c/extension-c-plugin.c
@@ -88,10 +88,10 @@ testing_extension_c_plugin_call_no_args (IntrospectionCallable *callable)
 {
 }
 
-static const gchar *
+static gchar *
 testing_extension_c_plugin_call_with_return (IntrospectionCallable *callable)
 {
-  return "Hello, World!";
+  return g_strdup ("Hello, World!");
 }
 
 static void
diff --git a/tests/libpeas/testing/testing-extension.c b/tests/libpeas/testing/testing-extension.c
index 21077df..e162b09 100644
--- a/tests/libpeas/testing/testing-extension.c
+++ b/tests/libpeas/testing/testing-extension.c
@@ -401,7 +401,7 @@ test_extension_call_with_return (PeasEngine     *engine,
 {
   PeasExtension *extension;
   IntrospectionCallable *callable;
-  const gchar *return_val = NULL;
+  gchar *return_val = NULL;
 
   extension = peas_engine_create_extension (engine, info,
                                             INTROSPECTION_TYPE_CALLABLE,
@@ -412,11 +412,13 @@ test_extension_call_with_return (PeasEngine     *engine,
   g_assert (peas_extension_call (extension, "call_with_return", &return_val));
   g_assert_cmpstr (return_val, ==, "Hello, World!");
 
+  g_free (return_val);
   return_val = NULL;
 
   return_val = introspection_callable_call_with_return (callable);
   g_assert_cmpstr (return_val, ==, "Hello, World!");
 
+  g_free (return_val);
   g_object_unref (extension);
 }
 


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