[glib] gdbusaddress: Fix memory leak when G_DBUS_DEBUG_ADDRESS is enabled



commit 456e02f280ede5e990bcfeb4faf6e6acba13d599
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Sat Oct 3 11:52:27 2015 +0100

    gdbusaddress: Fix memory leak when G_DBUS_DEBUG_ADDRESS is enabled
    
    Coverity CID: 1325374

 gio/gdbusaddress.c |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)
---
diff --git a/gio/gdbusaddress.c b/gio/gdbusaddress.c
index 6523623..4ef7b3c 100644
--- a/gio/gdbusaddress.c
+++ b/gio/gdbusaddress.c
@@ -1528,7 +1528,7 @@ g_dbus_address_get_for_bus_sync (GBusType       bus_type,
                                  GCancellable  *cancellable,
                                  GError       **error)
 {
-  gchar *ret;
+  gchar *ret, *s = NULL;
   const gchar *starter_bus;
   GError *local_error;
 
@@ -1541,8 +1541,10 @@ g_dbus_address_get_for_bus_sync (GBusType       bus_type,
     {
       guint n;
       _g_dbus_debug_print_lock ();
+      s = _g_dbus_enum_to_string (G_TYPE_BUS_TYPE, bus_type);
       g_print ("GDBus-debug:Address: In g_dbus_address_get_for_bus_sync() for bus type '%s'\n",
-               _g_dbus_enum_to_string (G_TYPE_BUS_TYPE, bus_type));
+               s);
+      g_free (s);
       for (n = 0; n < 3; n++)
         {
           const gchar *k;
@@ -1629,18 +1631,18 @@ g_dbus_address_get_for_bus_sync (GBusType       bus_type,
   if (G_UNLIKELY (_g_dbus_debug_address ()))
     {
       _g_dbus_debug_print_lock ();
+      s = _g_dbus_enum_to_string (G_TYPE_BUS_TYPE, bus_type);
       if (ret != NULL)
         {
           g_print ("GDBus-debug:Address: Returning address '%s' for bus type '%s'\n",
-                   ret,
-                   _g_dbus_enum_to_string (G_TYPE_BUS_TYPE, bus_type));
+                   ret, s);
         }
       else
         {
           g_print ("GDBus-debug:Address: Cannot look-up address bus type '%s': %s\n",
-                   _g_dbus_enum_to_string (G_TYPE_BUS_TYPE, bus_type),
-                   local_error ? local_error->message : "");
+                   s, local_error ? local_error->message : "");
         }
+      g_free (s);
       _g_dbus_debug_print_unlock ();
     }
 


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