app: in GimpCanvasBufferPreview, take strong ref on buffer

In GimpCanvasBufferPreview, take a strong reference on the preview
buffer, fixing a segfault in the foreground-select tool when
switching engines while the grayscale preview is active.

(cherry picked from commit ea864e2d5c)
This commit is contained in:
Ell
2020-02-03 20:01:03 +02:00
parent f4dc0fd147
commit a1eb04ea71

View File

@ -58,6 +58,7 @@ struct _GimpCanvasBufferPreviewPrivate
/* local function prototypes */ /* local function prototypes */
static void gimp_canvas_buffer_preview_dispose (GObject *object);
static void gimp_canvas_buffer_preview_set_property (GObject *object, static void gimp_canvas_buffer_preview_set_property (GObject *object,
guint property_id, guint property_id,
const GValue *value, const GValue *value,
@ -86,6 +87,7 @@ gimp_canvas_buffer_preview_class_init (GimpCanvasBufferPreviewClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpCanvasItemClass *item_class = GIMP_CANVAS_ITEM_CLASS (klass); GimpCanvasItemClass *item_class = GIMP_CANVAS_ITEM_CLASS (klass);
object_class->dispose = gimp_canvas_buffer_preview_dispose;
object_class->set_property = gimp_canvas_buffer_preview_set_property; object_class->set_property = gimp_canvas_buffer_preview_set_property;
object_class->get_property = gimp_canvas_buffer_preview_get_property; object_class->get_property = gimp_canvas_buffer_preview_get_property;
@ -104,6 +106,16 @@ gimp_canvas_buffer_preview_init (GimpCanvasBufferPreview *transform_preview)
{ {
} }
static void
gimp_canvas_buffer_preview_dispose (GObject *object)
{
GimpCanvasBufferPreviewPrivate *private = GET_PRIVATE (object);
g_clear_object (&private->buffer);
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void static void
gimp_canvas_buffer_preview_set_property (GObject *object, gimp_canvas_buffer_preview_set_property (GObject *object,
guint property_id, guint property_id,
@ -115,7 +127,7 @@ gimp_canvas_buffer_preview_set_property (GObject *object,
switch (property_id) switch (property_id)
{ {
case PROP_BUFFER: case PROP_BUFFER:
private->buffer = g_value_get_object (value); /* don't ref */ g_set_object (&private->buffer, g_value_get_object (value));
break; break;
default: default: