-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix crash during deallocation of self-referencing lists
When a list or any of its nodes references itself in a way that creates a cycle, their PyObjects may be visited multiple times during deallocation of the list. To handle this case cleanly, Python documentation recommends to release references held by such PyObject with Py_CLEAR. The macro works similarly to Py_XDECREF, but also sets the reference to NULL, which prevents repeated deallocation of the reference during subsequent visits of its owner PyObject. Most of the references held by llist PyObjects are released by Py_CLEAR. One of the exceptions was Py_None, which is a global variable that may not be set to NULL. To work around this limitation, llist module simply invoked Py_DECREF on Py_None during each visit of a garbage collected PyObject. Unfortunately this could release Py_None too many times, effectively 'stealing' references from other objects and eventually leading to a crash. To fix this issue, each linked list and node which holds a Py_None reference will now set a flag in its PyObject structure. The first release of the Py_None reference will clear the flag to prevent future traversal of this object from repeating the operation. Closes issue #11.
- Loading branch information
Showing
5 changed files
with
85 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* Copyright (c) 2019 Adam Jakubek, Rafał Gałczyński | ||
* Released under the MIT license (see attached LICENSE file). | ||
*/ | ||
|
||
#ifndef FLAGS_H | ||
#define FLAGS_H | ||
|
||
#define LLIST_HAS_PY_NONE_REF (0x01) | ||
|
||
#endif /* FLAGS_H */ |
This file contains 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
This file contains 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