Skip to content

raising an exception in a dict/code/function watcher callback will segfault on a DEALLOCATED event #102381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
carljm opened this issue Mar 2, 2023 · 0 comments · Fixed by #102382
Assignees
Labels
type-bug An unexpected behavior, bug, or error

Comments

@carljm
Copy link
Member

carljm commented Mar 2, 2023

Because the object we pass into the callback is dead (zero refcount), and if the callback raises an error we try to PyErr_WriteUnraisable with that object as context, which increfs and decrefs it, which recursively again tries to deallocate it, and we end up in infinite recursion and overflowing the stack.

There are various other ways a callback could trigger this issue. We shouldn't pass around dead objects; instead *_dealloc should temporarily resurrect it before calling the callback.

Linked PRs

@carljm carljm added the type-bug An unexpected behavior, bug, or error label Mar 2, 2023
@carljm carljm changed the title raising an exception in a dict watcher callback will segfault on a DEALLOCATED event raising an exception in a dict/code/function watcher callback will segfault on a DEALLOCATED event Mar 3, 2023
@carljm carljm self-assigned this Mar 3, 2023
carljm added a commit to carljm/cpython that referenced this issue Mar 3, 2023
carljm added a commit that referenced this issue Mar 8, 2023
carljm added a commit to carljm/cpython that referenced this issue Mar 8, 2023
* main:
  pythongh-102381: don't call watcher callback with dead object (python#102382)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant