diff options
author | Robin Watts <robin.watts@artifex.com> | 2016-09-16 14:18:09 +0100 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2016-09-16 17:26:28 +0100 |
commit | 117b8a8aa53ce1dcf813462b73c1d7d973494bc8 (patch) | |
tree | 45a9c979bc736f2f51641220a7796d6ad619b3f4 | |
parent | 7b9eb0d5608c2a76ae7af2b58809e2efeef25afa (diff) | |
download | mupdf-117b8a8aa53ce1dcf813462b73c1d7d973494bc8.tar.xz |
Tweak store handling of PDF document destroy.
When we destroy a PDF document, currently we bin everything
from the store. Instead, drop just the objects that are
specifically tied to that document.
Any object tied to the document has a pdf_obj with the
required document pointer in it as the key.
-rw-r--r-- | include/mupdf/pdf/resource.h | 1 | ||||
-rw-r--r-- | source/pdf/pdf-store.c | 18 | ||||
-rw-r--r-- | source/pdf/pdf-xref.c | 2 |
3 files changed, 20 insertions, 1 deletions
diff --git a/include/mupdf/pdf/resource.h b/include/mupdf/pdf/resource.h index f9f99da6..5c19f35a 100644 --- a/include/mupdf/pdf/resource.h +++ b/include/mupdf/pdf/resource.h @@ -7,6 +7,7 @@ void pdf_store_item(fz_context *ctx, pdf_obj *key, void *val, size_t itemsize); void *pdf_find_item(fz_context *ctx, fz_store_drop_fn *drop, pdf_obj *key); void pdf_remove_item(fz_context *ctx, fz_store_drop_fn *drop, pdf_obj *key); +void pdf_empty_store(fz_context *ctx, pdf_document *doc); /* * Structures used for managing resource locations and avoiding multiple diff --git a/source/pdf/pdf-store.c b/source/pdf/pdf-store.c index fa5cf76e..ccedbe0b 100644 --- a/source/pdf/pdf-store.c +++ b/source/pdf/pdf-store.c @@ -54,6 +54,8 @@ void pdf_store_item(fz_context *ctx, pdf_obj *key, void *val, size_t itemsize) { void *existing; + + assert(pdf_is_array(ctx, key) || pdf_is_dict(ctx, key) || pdf_is_indirect(ctx, key)); existing = fz_store_item(ctx, key, val, itemsize, &pdf_obj_store_type); assert(existing == NULL); (void)existing; /* Silence warning in release builds */ @@ -70,3 +72,19 @@ pdf_remove_item(fz_context *ctx, fz_store_drop_fn *drop, pdf_obj *key) { fz_remove_item(ctx, drop, key, &pdf_obj_store_type); } + +static int +pdf_filter_store(fz_context *ctx, void *doc_, void *key) +{ + pdf_document *doc = (pdf_document *)doc_; + pdf_obj *obj = (pdf_obj *)key; + pdf_document *key_doc = pdf_get_bound_document(ctx, obj); + + return (doc == key_doc); +} + +void +pdf_empty_store(fz_context *ctx, pdf_document *doc) +{ + fz_filter_store(ctx, pdf_filter_store, doc, &pdf_obj_store_type); +} diff --git a/source/pdf/pdf-xref.c b/source/pdf/pdf-xref.c index 30904d78..2d6bc1e0 100644 --- a/source/pdf/pdf-xref.c +++ b/source/pdf/pdf-xref.c @@ -1610,7 +1610,7 @@ pdf_drop_document_imp(fz_context *ctx, pdf_document *doc) pdf_drop_ocg(ctx, doc->ocg); - fz_empty_store(ctx); + pdf_empty_store(ctx, doc); pdf_lexbuf_fin(ctx, &doc->lexbuf.base); |