printing: Fix memory leak when listing Avahi printers
Return values of g_variant_get_child_value() were not unreffed correctly together with one value returned by g_variant_get(). Use g_variant_get_data() instead of copying each byte separately. https://bugzilla.gnome.org/show_bug.cgi?id=712799
This commit is contained in:
@@ -2626,10 +2626,11 @@ avahi_service_resolver_cb (GObject *source_object,
|
||||
GError *error = NULL;
|
||||
gchar *suffix = NULL;
|
||||
gchar *tmp;
|
||||
gsize length;
|
||||
gint interface;
|
||||
gint protocol;
|
||||
gint aprotocol;
|
||||
gint i, j;
|
||||
gint i;
|
||||
|
||||
output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object),
|
||||
res,
|
||||
@@ -2655,20 +2656,26 @@ avahi_service_resolver_cb (GObject *source_object,
|
||||
{
|
||||
child = g_variant_get_child_value (txt, i);
|
||||
|
||||
tmp = g_new0 (gchar, g_variant_n_children (child) + 1);
|
||||
for (j = 0; j < g_variant_n_children (child); j++)
|
||||
length = g_variant_get_size (child);
|
||||
if (length > 0)
|
||||
{
|
||||
tmp[j] = g_variant_get_byte (g_variant_get_child_value (child, j));
|
||||
}
|
||||
tmp = g_strndup (g_variant_get_data (child), length);
|
||||
|
||||
g_variant_unref (child);
|
||||
|
||||
if (g_str_has_prefix (tmp, "rp="))
|
||||
{
|
||||
suffix = g_strdup (tmp + 3);
|
||||
g_free (tmp);
|
||||
break;
|
||||
}
|
||||
|
||||
if (g_str_has_prefix (tmp, "rp="))
|
||||
{
|
||||
suffix = g_strdup (tmp + 3);
|
||||
g_free (tmp);
|
||||
break;
|
||||
}
|
||||
|
||||
g_free (tmp);
|
||||
else
|
||||
{
|
||||
g_variant_unref (child);
|
||||
}
|
||||
}
|
||||
|
||||
if (suffix)
|
||||
@@ -2702,6 +2709,7 @@ avahi_service_resolver_cb (GObject *source_object,
|
||||
g_free (suffix);
|
||||
}
|
||||
|
||||
g_variant_unref (txt);
|
||||
g_variant_unref (output);
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user