Skip to content

Fix leaked reference in _as_blocks() - #5074

Open
KetanHegde wants to merge 1 commit into
pymupdf:mainfrom
KetanHegde:fix-as-blocks-reference-leak
Open

Fix leaked reference in _as_blocks()#5074
KetanHegde wants to merge 1 commit into
pymupdf:mainfrom
KetanHegde:fix-as-blocks-reference-leak

Conversation

@KetanHegde

Copy link
Copy Markdown

Summary

Fixes #5067.

JM_EscapeStrFromBuffer() and PyUnicode_FromFormat() return new references. In _as_blocks(), text was wrapped with Py_BuildValue("O", text) before being passed to PyTuple_SET_ITEM(). The "O" format increments the reference count, while PyTuple_SET_ITEM() steals the reference it receives, leaving the original reference to text unreleased.

This change passes text directly to PyTuple_SET_ITEM(), transferring ownership to the tuple and avoiding the leaked reference.

Testing

  • Built PyMuPDF successfully after the change.
  • Ran the existing test suite successfully.

@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@KetanHegde

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

@KetanHegde

Copy link
Copy Markdown
Author

recheck

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory leak in extractBLOCKS (_as_blocks): text object reference never released

1 participant