Commit 332880da authored by Marius Wachtler's avatar Marius Wachtler

Fix some exception related leaks

parent 00e024af
...@@ -87,18 +87,28 @@ PyObject* PyErr_CreateExceptionInstance(PyObject* _type, PyObject* arg) { ...@@ -87,18 +87,28 @@ PyObject* PyErr_CreateExceptionInstance(PyObject* _type, PyObject* arg) {
PyObject_InitHcAttrs(&self->hcattrs); PyObject_InitHcAttrs(&self->hcattrs);
if (arg) { if (arg) {
self->args = PyTuple_Pack(1, arg); self->args = PyTuple_Pack(1, arg);
if (!self->args) if (!self->args) {
Py_DECREF(self);
return NULL; return NULL;
}
self->message = arg; self->message = arg;
} else { } else {
self->args = PyTuple_New(0); self->args = PyTuple_New(0);
if (!self->args) {
Py_DECREF(self);
return NULL;
}
self->message = PyString_FromString(""); self->message = PyString_FromString("");
if (!self->message) if (!self->message) {
Py_DECREF(self->args);
Py_DECREF(self);
return NULL; return NULL;
}
} }
return (PyObject*)self; return (PyObject*)self;
} else { } else {
// Fallback // Fallback
PyObject* rtn;
PyObject* args; PyObject* args;
if (arg == NULL) if (arg == NULL)
args = PyTuple_New(0); args = PyTuple_New(0);
...@@ -108,7 +118,9 @@ PyObject* PyErr_CreateExceptionInstance(PyObject* _type, PyObject* arg) { ...@@ -108,7 +118,9 @@ PyObject* PyErr_CreateExceptionInstance(PyObject* _type, PyObject* arg) {
if (args == NULL) if (args == NULL)
return NULL; return NULL;
return PyObject_Call(_type, args, NULL); rtn = PyObject_Call(_type, args, NULL);
Py_DECREF(args);
return rtn;
} }
} }
......
...@@ -45,6 +45,7 @@ void raiseSyntaxError(const char* msg, int lineno, int col_offset, llvm::StringR ...@@ -45,6 +45,7 @@ void raiseSyntaxError(const char* msg, int lineno, int col_offset, llvm::StringR
AUTO_DECREF(loc); AUTO_DECREF(loc);
auto args = BoxedTuple::create({ autoDecref(boxString(file)), autoDecref(boxInt(lineno)), None, loc }); auto args = BoxedTuple::create({ autoDecref(boxString(file)), autoDecref(boxInt(lineno)), None, loc });
AUTO_DECREF(args);
Box* exc = runtimeCall(SyntaxError, ArgPassSpec(2), autoDecref(boxString(msg)), args, NULL, NULL, NULL); Box* exc = runtimeCall(SyntaxError, ArgPassSpec(2), autoDecref(boxString(msg)), args, NULL, NULL, NULL);
assert(!PyErr_Occurred()); assert(!PyErr_Occurred());
throw ExcInfo(incref(exc->cls), exc, NULL); throw ExcInfo(incref(exc->cls), exc, NULL);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment