gdbusaddress: Fix memory leak when G_DBUS_DEBUG_ADDRESS is enabled

Coverity CID: 1325374
This commit is contained in:
Philip Withnall 2015-10-03 11:52:27 +01:00
parent 0f98b2f4ec
commit 456e02f280

View File

@ -1528,7 +1528,7 @@ g_dbus_address_get_for_bus_sync (GBusType bus_type,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gchar *ret; gchar *ret, *s = NULL;
const gchar *starter_bus; const gchar *starter_bus;
GError *local_error; GError *local_error;
@ -1541,8 +1541,10 @@ g_dbus_address_get_for_bus_sync (GBusType bus_type,
{ {
guint n; guint n;
_g_dbus_debug_print_lock (); _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_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++) for (n = 0; n < 3; n++)
{ {
const gchar *k; const gchar *k;
@ -1629,18 +1631,18 @@ g_dbus_address_get_for_bus_sync (GBusType bus_type,
if (G_UNLIKELY (_g_dbus_debug_address ())) if (G_UNLIKELY (_g_dbus_debug_address ()))
{ {
_g_dbus_debug_print_lock (); _g_dbus_debug_print_lock ();
s = _g_dbus_enum_to_string (G_TYPE_BUS_TYPE, bus_type);
if (ret != NULL) if (ret != NULL)
{ {
g_print ("GDBus-debug:Address: Returning address '%s' for bus type '%s'\n", g_print ("GDBus-debug:Address: Returning address '%s' for bus type '%s'\n",
ret, ret, s);
_g_dbus_enum_to_string (G_TYPE_BUS_TYPE, bus_type));
} }
else else
{ {
g_print ("GDBus-debug:Address: Cannot look-up address bus type '%s': %s\n", 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), s, local_error ? local_error->message : "");
local_error ? local_error->message : "");
} }
g_free (s);
_g_dbus_debug_print_unlock (); _g_dbus_debug_print_unlock ();
} }