Clear the in-doc flag when removing a page from the opened page list. 1.25.x-testing 1.25.5
authorSebastian Rasmussen <[email protected]>
Thu, 13 Mar 2025 17:23:49 +0000 (18:23 +0100)
committerSebastian Rasmussen <[email protected]>
Thu, 13 Mar 2025 17:55:42 +0000 (18:55 +0100)
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.

source/pdf/pdf-page.c

index e07262df949875e5478ac16c1c4a0ceba3a6ef61..f9d8050782ff0953666b49a0a8bc2909b5fd20eb 100644 (file)
@@ -1280,6 +1280,7 @@ void pdf_nuke_page(fz_context *ctx, pdf_page *page)
        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)