summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/cbz/mucbz.c1
-rw-r--r--source/fitz/document.c11
-rw-r--r--source/img/muimage.c1
-rw-r--r--source/pdf/pdf-xref.c1
-rw-r--r--source/tiff/mutiff.c1
-rw-r--r--source/tools/mjsgen.c2
-rw-r--r--source/tools/mudraw.c6
-rw-r--r--source/xps/xps-zip.c1
8 files changed, 18 insertions, 6 deletions
diff --git a/source/cbz/mucbz.c b/source/cbz/mucbz.c
index 9b548125..6951e798 100644
--- a/source/cbz/mucbz.c
+++ b/source/cbz/mucbz.c
@@ -263,6 +263,7 @@ cbz_rebind(cbz_document *doc, fz_context *ctx)
static void
cbz_init_document(cbz_document *doc)
{
+ doc->super.refs = 1;
doc->super.close = (fz_document_close_fn *)cbz_close_document;
doc->super.count_pages = (fz_document_count_pages_fn *)cbz_count_pages;
doc->super.load_page = (fz_document_load_page_fn *)cbz_load_page;
diff --git a/source/fitz/document.c b/source/fitz/document.c
index ad2e84ba..64de1bc0 100644
--- a/source/fitz/document.c
+++ b/source/fitz/document.c
@@ -142,10 +142,17 @@ fz_open_document(fz_context *ctx, const char *filename)
return NULL;
}
+fz_document *
+fz_keep_document(fz_document *doc)
+{
+ ++doc->refs;
+ return doc;
+}
+
void
-fz_close_document(fz_document *doc)
+fz_drop_document(fz_document *doc)
{
- if (doc && doc->close)
+ if (doc && --doc->refs == 0 && doc->close)
doc->close(doc);
}
diff --git a/source/img/muimage.c b/source/img/muimage.c
index 7e0f56ab..21fd6261 100644
--- a/source/img/muimage.c
+++ b/source/img/muimage.c
@@ -150,6 +150,7 @@ image_rebind(image_document *doc, fz_context *ctx)
static void
image_init_document(image_document *doc)
{
+ doc->super.refs = 1;
doc->super.close = (fz_document_close_fn *)image_close_document;
doc->super.count_pages = (fz_document_count_pages_fn *)image_count_pages;
doc->super.load_page = (fz_document_load_page_fn *)image_load_page;
diff --git a/source/pdf/pdf-xref.c b/source/pdf/pdf-xref.c
index ec2ff8f5..172c13e6 100644
--- a/source/pdf/pdf-xref.c
+++ b/source/pdf/pdf-xref.c
@@ -2268,6 +2268,7 @@ pdf_new_document(fz_context *ctx, fz_stream *file)
{
pdf_document *doc = fz_malloc_struct(ctx, pdf_document);
+ doc->super.refs = 1;
doc->super.close = (fz_document_close_fn *)pdf_close_document;
doc->super.needs_password = (fz_document_needs_password_fn *)pdf_needs_password;
doc->super.authenticate_password = (fz_document_authenticate_password_fn *)pdf_authenticate_password;
diff --git a/source/tiff/mutiff.c b/source/tiff/mutiff.c
index a48165bf..ae9a7a72 100644
--- a/source/tiff/mutiff.c
+++ b/source/tiff/mutiff.c
@@ -179,6 +179,7 @@ tiff_rebind(tiff_document *doc, fz_context *ctx)
static void
tiff_init_document(tiff_document *doc)
{
+ doc->super.refs = 1;
doc->super.close = (fz_document_close_fn *)tiff_close_document;
doc->super.count_pages = (fz_document_count_pages_fn *)tiff_count_pages;
doc->super.load_page = (fz_document_load_page_fn *)tiff_load_page;
diff --git a/source/tools/mjsgen.c b/source/tools/mjsgen.c
index 3e11fde3..1987e76d 100644
--- a/source/tools/mjsgen.c
+++ b/source/tools/mjsgen.c
@@ -278,7 +278,7 @@ int main(int argc, char **argv)
processpages(ctx, doc);
- fz_close_document(doc);
+ fz_drop_document(doc);
}
fz_catch(ctx)
{
diff --git a/source/tools/mudraw.c b/source/tools/mudraw.c
index 420ca1dc..734429da 100644
--- a/source/tools/mudraw.c
+++ b/source/tools/mudraw.c
@@ -1067,7 +1067,7 @@ int main(int argc, char **argv)
if (showxml || showtext == TEXT_XML)
fz_printf(out, "</document>\n");
- fz_close_document(doc);
+ fz_drop_document(doc);
doc = NULL;
}
fz_catch(ctx)
@@ -1075,7 +1075,7 @@ int main(int argc, char **argv)
if (!ignore_errors)
fz_rethrow(ctx);
- fz_close_document(doc);
+ fz_drop_document(doc);
doc = NULL;
fz_warn(ctx, "ignoring error in '%s'", filename);
}
@@ -1083,7 +1083,7 @@ int main(int argc, char **argv)
}
fz_catch(ctx)
{
- fz_close_document(doc);
+ fz_drop_document(doc);
fprintf(stderr, "error: cannot draw '%s'\n", filename);
errored = 1;
}
diff --git a/source/xps/xps-zip.c b/source/xps/xps-zip.c
index 8b96773f..1dbd103c 100644
--- a/source/xps/xps-zip.c
+++ b/source/xps/xps-zip.c
@@ -254,6 +254,7 @@ xps_rebind(xps_document *doc, fz_context *ctx)
static void
xps_init_document(xps_document *doc)
{
+ doc->super.refs = 1;
doc->super.close = (fz_document_close_fn *)xps_close_document;
doc->super.load_outline = (fz_document_load_outline_fn *)xps_load_outline;
doc->super.count_pages = (fz_document_count_pages_fn *)xps_count_pages;