summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-11-06 23:12:35 +0200
committerGitHub <noreply@github.com>2017-11-06 23:12:35 +0200
commit138a2ff3f6db37468f3c7509f69c984792fd49a0 (patch)
treea690cf99d1c312c504c098f72191e0a52b2d40ba
parent113039ae96e670b8f7441d5b1d2c40d9b0b75f56 (diff)
downloadsimplejson-138a2ff3f6db37468f3c7509f69c984792fd49a0.tar.gz
bpo-31095: fix potential crash during GC (#187)
Original patch by INADA Naoki.
-rw-r--r--simplejson/_speedups.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/simplejson/_speedups.c b/simplejson/_speedups.c
index e4620b5..bfd053a 100644
--- a/simplejson/_speedups.c
+++ b/simplejson/_speedups.c
@@ -1358,7 +1358,8 @@ py_encode_basestring_ascii(PyObject* self UNUSED, PyObject *pystr)
static void
scanner_dealloc(PyObject *self)
{
- /* Deallocate scanner object */
+ /* bpo-31095: UnTrack is needed before calling any callbacks */
+ PyObject_GC_UnTrack(self);
scanner_clear(self);
Py_TYPE(self)->tp_free(self);
}
@@ -3208,7 +3209,8 @@ bail:
static void
encoder_dealloc(PyObject *self)
{
- /* Deallocate Encoder */
+ /* bpo-31095: UnTrack is needed before calling any callbacks */
+ PyObject_GC_UnTrack(self);
encoder_clear(self);
Py_TYPE(self)->tp_free(self);
}