Skip to content

Commit 7775923

Browse files
committed
Decref heap types
1 parent ecb4c19 commit 7775923

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

asyncpg/protocol/record/recordobj.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ record_dealloc(PyObject *self)
173173
ApgRecordObject *o = (ApgRecordObject *)self;
174174
Py_ssize_t i;
175175
Py_ssize_t len = Py_SIZE(o);
176+
PyTypeObject *tp = Py_TYPE(o);
176177
record_module_state *state;
178+
int skip_dealloc = 0;
177179

178180
state = find_module_state_by_def(Py_TYPE(o));
179181
if (state == NULL) {
@@ -193,19 +195,19 @@ record_dealloc(PyObject *self)
193195
Py_XDECREF(o->ob_item[i]);
194196
}
195197

196-
if (len < ApgRecord_MAXSAVESIZE && Py_TYPE(o) == state->ApgRecord_Type) {
198+
if (len < ApgRecord_MAXSAVESIZE && tp == state->ApgRecord_Type) {
197199
record_freelist_state *freelist = get_freelist_state(state);
198200
if (freelist != NULL && freelist->numfree[len] < ApgRecord_MAXFREELIST) {
199201
o->ob_item[0] = (PyObject *)freelist->freelist[len];
200202
freelist->numfree[len]++;
201203
freelist->freelist[len] = o;
202-
}
203-
else {
204-
Py_TYPE(o)->tp_free((PyObject *)o);
204+
skip_dealloc = 1;
205205
}
206206
}
207-
else {
208-
Py_TYPE(o)->tp_free((PyObject *)o);
207+
208+
if (!skip_dealloc) {
209+
tp->tp_free(self);
210+
Py_DECREF(tp);
209211
}
210212

211213
Py_TRASHCAN_END
@@ -392,7 +394,7 @@ record_richcompare(PyObject *v, PyObject *w, int op)
392394
cmp = vlen >= wlen;
393395
break;
394396
default:
395-
return NULL; /* cannot happen */
397+
Py_UNREACHABLE();
396398
}
397399
if (cmp) {
398400
Py_RETURN_TRUE;
@@ -776,9 +778,11 @@ typedef struct {
776778
static void
777779
record_iter_dealloc(ApgRecordIterObject *it)
778780
{
781+
PyTypeObject *tp = Py_TYPE(it);
779782
PyObject_GC_UnTrack(it);
780783
Py_CLEAR(it->it_seq);
781784
PyObject_GC_Del(it);
785+
Py_DECREF(tp);
782786
}
783787

784788
static int
@@ -870,10 +874,12 @@ typedef struct {
870874
static void
871875
record_items_dealloc(ApgRecordItemsObject *it)
872876
{
877+
PyTypeObject *tp = Py_TYPE(it);
873878
PyObject_GC_UnTrack(it);
874879
Py_CLEAR(it->it_key_iter);
875880
Py_CLEAR(it->it_seq);
876881
PyObject_GC_Del(it);
882+
Py_DECREF(tp);
877883
}
878884

879885
static int
@@ -997,10 +1003,12 @@ record_new_items_iter(ApgRecordObject *r, const record_module_state *state)
9971003
static void
9981004
record_desc_dealloc(ApgRecordDescObject *o)
9991005
{
1006+
PyTypeObject *tp = Py_TYPE(o);
10001007
PyObject_GC_UnTrack(o);
10011008
Py_CLEAR(o->mapping);
10021009
Py_CLEAR(o->keys);
10031010
PyObject_GC_Del(o);
1011+
Py_DECREF(tp);
10041012
}
10051013

10061014
static int

0 commit comments

Comments
 (0)