Skip to content

Commit 99cc629

Browse files
committed
Issue #15142: Fix reference leak when deallocating instances of types created using PyType_FromSpec().
1 parent b8dc3ab commit 99cc629

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.2.4
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #15142: Fix reference leak when deallocating instances of types
14+
created using PyType_FromSpec().
15+
1316
- Issue #10053: Don't close FDs when FileIO.__init__ fails. Loosely based on
1417
the work by Hirokazu Yamamoto.
1518

Objects/typeobject.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,6 +2387,12 @@ PyType_FromSpec(PyType_Spec *spec)
23872387
res->ht_type.tp_doc = tp_doc;
23882388
}
23892389
}
2390+
if (res->ht_type.tp_dealloc == NULL) {
2391+
/* It's a heap type, so needs the heap types' dealloc.
2392+
subtype_dealloc will call the base type's tp_dealloc, if
2393+
necessary. */
2394+
res->ht_type.tp_dealloc = subtype_dealloc;
2395+
}
23902396

23912397
if (PyType_Ready(&res->ht_type) < 0)
23922398
goto fail;

0 commit comments

Comments
 (0)