summaryrefslogtreecommitdiffstats
path: root/Objects/exceptions.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/exceptions.c')
-rw-r--r--Objects/exceptions.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index db5e3da..e44ce72 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -2282,8 +2282,12 @@ MemoryError_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyBaseExceptionObject *self;
- if (type != (PyTypeObject *) PyExc_MemoryError)
+ /* If this is a subclass of MemoryError, don't use the freelist
+ * and just return a fresh object */
+ if (type != (PyTypeObject *) PyExc_MemoryError) {
return BaseException_new(type, args, kwds);
+ }
+
if (memerrors_freelist == NULL)
return BaseException_new(type, args, kwds);
/* Fetch object from freelist and revive it */
@@ -2303,8 +2307,14 @@ MemoryError_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static void
MemoryError_dealloc(PyBaseExceptionObject *self)
{
- _PyObject_GC_UNTRACK(self);
BaseException_clear(self);
+
+ if (!Py_IS_TYPE(self, (PyTypeObject *) PyExc_MemoryError)) {
+ return Py_TYPE(self)->tp_free((PyObject *)self);
+ }
+
+ _PyObject_GC_UNTRACK(self);
+
if (memerrors_numfree >= MEMERRORS_SAVE)
Py_TYPE(self)->tp_free((PyObject *)self);
else {