aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.me.uk>2018-10-30 18:17:54 +0100
committerThomas White <taw@bitwiz.me.uk>2018-10-30 18:17:54 +0100
commitca4ecaf2b06e50fc2026e35b946409b719f72425 (patch)
tree887e7e2b20ae132ed53f29744d93c8901db9e84d
parent91f680b08931aaa43df551d18fdd4b6638fbac7b (diff)
Fix reference counting for presentation/stylesheet GFiles
-rw-r--r--src/narrative_window.c1
-rw-r--r--src/presentation.c15
2 files changed, 15 insertions, 1 deletions
diff --git a/src/narrative_window.c b/src/narrative_window.c
index 3f936e0..98001a9 100644
--- a/src/narrative_window.c
+++ b/src/narrative_window.c
@@ -147,6 +147,7 @@ static gint saveas_response_sig(GtkWidget *d, gint response,
show_error(si->nw, _("Failed to save presentation"));
}
+ /* save_presentation keeps a reference to both of these */
g_object_unref(file);
g_object_unref(ssfile);
diff --git a/src/presentation.c b/src/presentation.c
index fd55bf7..28f82a2 100644
--- a/src/presentation.c
+++ b/src/presentation.c
@@ -110,6 +110,7 @@ static void find_and_load_stylesheet(struct presentation *p, GFile *file)
}
/* Last resort is NULL stylesheet and SCInterpreter's defaults */
+ /* We keep a reference to the GFile */
}
@@ -168,6 +169,13 @@ int save_presentation(struct presentation *p, GFile *file, GFile *ssfile)
if ( sr ) {
fprintf(stderr, _("Couldn't save stylesheet\n"));
}
+ if ( p->stylesheet_from != ssfile ) {
+ if ( p->stylesheet_from != NULL ) {
+ g_object_unref(p->stylesheet_from);
+ }
+ p->stylesheet_from = ssfile;
+ g_object_ref(p->stylesheet_from);
+ }
} else {
fprintf(stderr, _("Not updating default stylesheet\n"));
sr = 0;
@@ -176,7 +184,12 @@ int save_presentation(struct presentation *p, GFile *file, GFile *ssfile)
if ( r || sr ) return 1;
imagestore_set_parent(p->is, g_file_get_parent(file));
- p->file = file;
+
+ if ( p->file != file ) {
+ if ( p->file != NULL ) g_object_unref(p->file);
+ p->file = file;
+ g_object_ref(p->file);
+ }
p->saved = 1;
update_titlebar(p->narrative_window);
return 0;