[gtksourceview/gnome-3-24] completion: fix improper memory use for background-color



commit e938da84d5c6cb311c61acb902c92d652a5b920f
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jul 30 17:06:36 2018 -0700

    completion: fix improper memory use for background-color
    
    gtk_style_context_get() returns a boxed copy of the GdkRGBA for the given
    state. Instead of providing a GdkRGBA* as the parameter, we need to provide
    a GdkRGBA** and free it upon exit from the function.
    
    This fixes a leak detected by LSAN. While the previous usage could have
    resulted in incorrect visuals, it was larger than a pointer size and
    therefore should not have caused any memory corruption.

 gtksourceview/gtksourcecompletion.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
---
diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index f0e000cf..fda89e3a 100644
--- a/gtksourceview/gtksourcecompletion.c
+++ b/gtksourceview/gtksourcecompletion.c
@@ -2028,7 +2028,7 @@ init_tree_view (GtkSourceCompletion *completion,
        GtkTreeViewColumn *column;
        GtkCellRenderer *cell_renderer;
        GtkStyleContext *style_context;
-       GdkRGBA background_color;
+       GdkRGBA* background_color = NULL;
        GdkRGBA foreground_color;
 
        completion->priv->tree_view_proposals = GTK_TREE_VIEW (gtk_builder_get_object (builder, 
"tree_view_proposals"));
@@ -2094,7 +2094,7 @@ init_tree_view (GtkSourceCompletion *completion,
        gtk_style_context_restore (style_context);
 
        g_object_set (cell_renderer,
-                     "cell-background-rgba", &background_color,
+                     "cell-background-rgba", background_color,
                      NULL);
 
        g_object_bind_property (completion, "show-icons",
@@ -2116,7 +2116,7 @@ init_tree_view (GtkSourceCompletion *completion,
 
        g_object_set (cell_renderer,
                      "foreground-rgba", &foreground_color,
-                     "cell-background-rgba", &background_color,
+                     "cell-background-rgba", background_color,
                      NULL);
 
        /* Accelerators cell renderer */
@@ -2132,7 +2132,7 @@ init_tree_view (GtkSourceCompletion *completion,
 
        g_object_set (cell_renderer,
                      "foreground-rgba", &foreground_color,
-                     "cell-background-rgba", &background_color,
+                     "cell-background-rgba", background_color,
                      NULL);
 
        gtk_tree_view_column_set_cell_data_func (column,
@@ -2146,6 +2146,8 @@ init_tree_view (GtkSourceCompletion *completion,
                                 G_CALLBACK (accelerators_notify_cb),
                                 column,
                                 0);
+
+       gdk_rgba_free (background_color);
 }
 
 static void


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