Skip to content

Commit

Permalink
Fix GVariant reference leaks
Browse files Browse the repository at this point in the history
There is memory leakage that is proportional to amount of incoming
dbus traffic. Analyzing valgrind logs points towards GVariant
reference leaks from functions like validate_arg0_name().

Documentation for g_variant_get_child_value() states: "The returned
value is never floating. You should free it with g_variant_unref()
when you're done with it." Many functions omit such cleanup actions.

Use g_autoptr(GVariant) type for variables that are used for storing
g_variant_get_child_value() return value - like how it is already done
in get_arg0_string().

Signed-off-by: Simo Piiroinen <[email protected]>
  • Loading branch information
spiiroin authored and GeorgesStavracas committed Apr 26, 2024
1 parent f87dab5 commit d6da6ed
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions flatpak-proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -2092,7 +2092,8 @@ static gboolean
validate_arg0_match (FlatpakProxyClient *client, Buffer *buffer)
{
GDBusMessage *message = g_dbus_message_new_from_blob (buffer->data, buffer->size, 0, NULL);
GVariant *body, *arg0;
GVariant *body;
g_autoptr(GVariant) arg0 = NULL;
const char *match;
gboolean res = TRUE;

Expand All @@ -2114,7 +2115,8 @@ static gboolean
validate_arg0_name (FlatpakProxyClient *client, Buffer *buffer, FlatpakPolicy required_policy, FlatpakPolicy *has_policy)
{
GDBusMessage *message = g_dbus_message_new_from_blob (buffer->data, buffer->size, 0, NULL);
GVariant *body, *arg0;
GVariant *body;
g_autoptr(GVariant) arg0 = NULL;
const char *name;
FlatpakPolicy name_policy;
gboolean res = FALSE;
Expand Down Expand Up @@ -2147,7 +2149,8 @@ static Buffer *
filter_names_list (FlatpakProxyClient *client, Buffer *buffer)
{
GDBusMessage *message = g_dbus_message_new_from_blob (buffer->data, buffer->size, 0, NULL);
GVariant *body, *arg0, *new_names;
GVariant *body, *new_names;
g_autoptr(GVariant) arg0 = NULL;
const gchar **names;
int i;
GVariantBuilder builder;
Expand Down Expand Up @@ -2193,7 +2196,10 @@ static gboolean
should_filter_name_owner_changed (FlatpakProxyClient *client, Buffer *buffer)
{
GDBusMessage *message = g_dbus_message_new_from_blob (buffer->data, buffer->size, 0, NULL);
GVariant *body, *arg0, *arg1, *arg2;
GVariant *body;
g_autoptr(GVariant) arg0 = NULL;
g_autoptr(GVariant) arg1 = NULL;
g_autoptr(GVariant) arg2 = NULL;
const gchar *name, *new;
gboolean filter = TRUE;

Expand Down Expand Up @@ -2389,7 +2395,8 @@ static void
queue_wildcard_initial_name_ops (FlatpakProxyClient *client, Header *header, Buffer *buffer)
{
GDBusMessage *decoded_message = g_dbus_message_new_from_blob (buffer->data, buffer->size, 0, NULL);
GVariant *body, *arg0;
GVariant *body;
g_autoptr(GVariant) arg0 = NULL;

if (decoded_message != NULL &&
header->type == G_DBUS_MESSAGE_TYPE_METHOD_RETURN &&
Expand Down

0 comments on commit d6da6ed

Please sign in to comment.