When the last reference to a page is dropped, there is a check to see if it
belongs to a document. If it does not, the page object is freed immediately.
If the page belongs to a document, then freeing of the page object is delayed
until the last reference of the document is dropped.
Deleting a page requires syncing the document's list of opened pages.
If the page is no longer part of a document, it will be nuked from this list.
The assumption is that either there are no more references to the page, causing
the page to be freed immediately, or the caller holds all remaining references,
causing the page to be freed when the last of its references are dropped.
When a page is removed from the document, its in-document flag must be cleared.
Otherwise, when dropping the page reference from the list, the page object will
not be freed, even if this is the last reference to the page. Instead, since the
in-document flag is set, the page is assuming that the document owning it will
free the page object, but this will never happen, leading to a leak.
pdf_nuke_annots(ctx, page);
pdf_drop_obj(ctx, page->obj);
page->obj = NULL;
+ page->super.in_doc = 0;
}
void pdf_sync_page(fz_context *ctx, pdf_page *page)