Free registry callback after capsule construction errors#7
Open
jeet-dekivadia wants to merge 1 commit into
Open
Free registry callback after capsule construction errors#7jeet-dekivadia wants to merge 1 commit into
jeet-dekivadia wants to merge 1 commit into
Conversation
Signed-off-by: Jeet Dekivadia <jeet.university@gmail.com>
Author
|
Small follow-up for review context. The failure path is narrowly scoped: registry setup allocates the weakref callback definition separately, then PyCapsule_New can fail while constructing the registry capsule. This patch sends that error path through the existing registry cleanup helper so the callback allocation is released with the rest of the partially built registry. Validation from preparation: git diff --check; a Python.h/pymetabind.h syntax probe with python3-config includes; a compiled smoke extension imported on CPython 3.9 and 3.13 and called pymb_get_registry twice; and a focused forced PyCapsule_New failure harness observed the tracked header allocations and frees balance at 2 and 2. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6.
pymb_get_registry()allocates the registry and its weakref callback definition separately. IfPyCapsule_New()then fails, the error path freed the registry struct directly and skipped the callback allocation.Route that path through the existing
pymb_registry_free()helper. It releases the callback definition and the registry together, matching the capsule destructor path without changing successful initialization.Validation:
git diff --checkprintf '#include <Python.h>\n#include <stdint.h>\n#include <stdlib.h>\n#include "pymetabind.h"\n' | cc -x c -fsyntax-only - $(python3-config --includes)pymb_get_registry()twice on CPython 3.9 and 3.13PyCapsule_New()to fail after registry setup and observed2tracked header allocations and2frees