Index: backend/impress/impress-document.c
===================================================================
--- backend/impress/impress-document.c	(revision 2248)
+++ backend/impress/impress-document.c	(working copy)
@@ -399,15 +399,40 @@
 impress_document_finalize (GObject *object)
 {
   ImpressDocument *impress_document = IMPRESS_DOCUMENT (object);
+  if (impress_document == NULL)
+    	return;
 
-  g_mutex_free (impress_document->mutex);
+  if (impress_document->mutex)
+  {
+	  g_mutex_free (impress_document->mutex);
+	  impress_document->mutex = NULL;
+  }
+  if (impress_document->imp)
+  {
+	  imp_close (impress_document->imp);
+	  impress_document->imp = NULL;
+  }
+  if (impress_document->ctx)
+  {
+	  imp_delete_context (impress_document->ctx);
+	  impress_document->ctx = NULL;
+  }
+  if (impress_document->pango_ctx)
+  {
+	  pango_font_description_free (impress_document->pango_ctx);
+	  impress_document->pango_ctx = NULL;
+  }
+  if (impress_document->pixmap)
+  {
+	  g_object_unref (G_OBJECT (impress_document->pixmap));
+	  impress_document->pixmap = NULL;
+  }
+  if (impress_document->gc)
+  {
+	  g_object_unref (impress_document->gc);
+	  impress_document->gc = NULL;
+  }
 
-  imp_close (impress_document->imp);
-  imp_delete_context (impress_document->ctx);
-  g_free (impress_document->pango_ctx);
-  g_object_unref (G_OBJECT (impress_document->pixmap));
-  g_object_unref (impress_document->gc);
-
   G_OBJECT_CLASS (impress_document_parent_class)->finalize (object);
 }
 
Index: backend/impress/document.c
===================================================================
--- backend/impress/document.c	(revision 2248)
+++ backend/impress/document.c	(working copy)
@@ -133,6 +133,8 @@
 void
 imp_close(ImpDoc *doc)
 {
+	if (doc == NULL)
+		return;
 	if (doc->stack) iks_stack_delete(doc->stack);
 	if (doc->zfile) zip_close(doc->zfile);
 	free(doc);
