]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-148688: Fix _BlocksOutputBuffer_Finish() double free (#148689)
authorVictor Stinner <vstinner@python.org>
Sat, 18 Apr 2026 09:56:56 +0000 (11:56 +0200)
committerGitHub <noreply@github.com>
Sat, 18 Apr 2026 09:56:56 +0000 (09:56 +0000)
commitd61fcf834d197f0113a6a507fdbecc1545d9d483
tree9af9f9f0e7cb2f30212163fce3e658efd90360a1
parente9bbf8617dff942360b5d800769c00440dc93bac
gh-148688: Fix _BlocksOutputBuffer_Finish() double free (#148689)

If _BlocksOutputBuffer_Finish() fails (memory allocation failure),
PyBytesWriter_Discard() is called on the writer. Then if
_BlocksOutputBuffer_OnError() is called, it calls again
PyBytesWriter_Discard() causing a double free.

Fix _BlocksOutputBuffer_Finish() by setting buffer->writer to NULL,
so _BlocksOutputBuffer_OnError() does nothing instead of calling
PyBytesWriter_Discard() again.
Include/internal/pycore_blocks_output_buffer.h
Misc/NEWS.d/next/Library/2026-04-17-16-31-58.gh-issue-148688.vVugFn.rst [new file with mode: 0644]