[glib] GDBusMethodInvocation: leak and potential crash



commit a8811fb86477d162379694eb8a4480a11ee8cc71
Author: Patrick Ohly <patrick ohly intel com>
Date:   Thu Mar 7 18:44:44 2013 +0100

    GDBusMethodInvocation: leak and potential crash
    
    _g_dbus_method_invocation_new is said to allow method_info == NULL,
    but will crash inside g_dbus_method_info_ref when the method_info
    really is NULL, because g_dbus_method_info_ref does not allow NULL as
    parameter. Fixed by checking for NULL in _g_dbus_method_invocation_new
    itself.
    
    The leak itself happens because _g_dbus_method_invocation_new stores a
    new reference to the method_info without also unreferencing it. Fixed
    by adding the missing unref, protected by an if because the pointer
    may be NULL.
    
    Fixes https://bugzilla.gnome.org/show_bug.cgi?id=695376

 gio/gdbusmethodinvocation.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/gio/gdbusmethodinvocation.c b/gio/gdbusmethodinvocation.c
index 979468e..12c04db 100644
--- a/gio/gdbusmethodinvocation.c
+++ b/gio/gdbusmethodinvocation.c
@@ -85,7 +85,7 @@ struct _GDBusMethodInvocation
   gchar           *object_path;
   gchar           *interface_name;
   gchar           *method_name;
-  const GDBusMethodInfo *method_info;
+  GDBusMethodInfo *method_info;
   GDBusConnection *connection;
   GDBusMessage    *message;
   GVariant        *parameters;
@@ -103,6 +103,8 @@ g_dbus_method_invocation_finalize (GObject *object)
   g_free (invocation->object_path);
   g_free (invocation->interface_name);
   g_free (invocation->method_name);
+  if (invocation->method_info)
+      g_dbus_method_info_unref (invocation->method_info);
   g_object_unref (invocation->connection);
   g_object_unref (invocation->message);
   g_variant_unref (invocation->parameters);
@@ -328,7 +330,8 @@ _g_dbus_method_invocation_new (const gchar           *sender,
   invocation->object_path = g_strdup (object_path);
   invocation->interface_name = g_strdup (interface_name);
   invocation->method_name = g_strdup (method_name);
-  invocation->method_info = g_dbus_method_info_ref ((GDBusMethodInfo *)method_info);
+  if (method_info)
+    invocation->method_info = g_dbus_method_info_ref ((GDBusMethodInfo *)method_info);
   invocation->connection = g_object_ref (connection);
   invocation->message = g_object_ref (message);
   invocation->parameters = g_variant_ref (parameters);


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