Issue #3275 - Crash when opening an image after closing existing image

In gimp_open_dialog_set_image(), use a weak pointer for storing the
current image, to avoid a segfault in file_open_dialog_response()
if the active image at the time of the open action has been closed
before confirming the dialog.
This commit is contained in:
Ell 2019-04-20 14:30:43 -04:00
parent eda8b717d5
commit b01113741e
2 changed files with 43 additions and 6 deletions

View file

@ -139,10 +139,13 @@ file_open_dialog_response (GtkWidget *dialog,
{ {
if (! file_dialog->image) if (! file_dialog->image)
{ {
file_dialog->image = file_open_dialog_open_image (dialog, gimp_open_dialog_set_image (
gimp, open_dialog,
file, file_open_dialog_open_image (dialog,
file_dialog->file_proc); gimp,
file,
file_dialog->file_proc),
TRUE);
if (file_dialog->image) if (file_dialog->image)
{ {

View file

@ -37,15 +37,25 @@
#include "gimp-intl.h" #include "gimp-intl.h"
/* local function prototypes */
static void gimp_open_dialog_dispose (GObject *object);
G_DEFINE_TYPE (GimpOpenDialog, gimp_open_dialog, G_DEFINE_TYPE (GimpOpenDialog, gimp_open_dialog,
GIMP_TYPE_FILE_DIALOG) GIMP_TYPE_FILE_DIALOG)
#define parent_class gimp_open_dialog_parent_class #define parent_class gimp_open_dialog_parent_class
/* private functions */
static void static void
gimp_open_dialog_class_init (GimpOpenDialogClass *klass) gimp_open_dialog_class_init (GimpOpenDialogClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = gimp_open_dialog_dispose;
} }
static void static void
@ -53,6 +63,14 @@ gimp_open_dialog_init (GimpOpenDialog *dialog)
{ {
} }
static void
gimp_open_dialog_dispose (GObject *object)
{
gimp_open_dialog_set_image (GIMP_OPEN_DIALOG (object), NULL, FALSE);
G_OBJECT_CLASS (parent_class)->dispose (object);
}
/* public functions */ /* public functions */
@ -83,9 +101,25 @@ gimp_open_dialog_set_image (GimpOpenDialog *dialog,
GimpImage *image, GimpImage *image,
gboolean open_as_layers) gboolean open_as_layers)
{ {
GimpFileDialog *file_dialog;
g_return_if_fail (GIMP_IS_OPEN_DIALOG (dialog)); g_return_if_fail (GIMP_IS_OPEN_DIALOG (dialog));
g_return_if_fail (image == NULL || GIMP_IS_IMAGE (image)); g_return_if_fail (image == NULL || GIMP_IS_IMAGE (image));
GIMP_FILE_DIALOG (dialog)->image = image; file_dialog = GIMP_FILE_DIALOG (dialog);
dialog->open_as_layers = open_as_layers;
if (file_dialog->image)
{
g_object_remove_weak_pointer (G_OBJECT (file_dialog->image),
(gpointer *) &file_dialog->image);
}
file_dialog->image = image;
dialog->open_as_layers = open_as_layers;
if (file_dialog->image)
{
g_object_add_weak_pointer (G_OBJECT (file_dialog->image),
(gpointer *) &file_dialog->image);
}
} }