Commit 175ebc10 authored by Denis Bilenko's avatar Denis Bilenko

Do not save traceback object in Hub.switch() as that can leak it; only save an exception object

parent 477e7ca2
...@@ -584,7 +584,8 @@ def get_header_version(): ...@@ -584,7 +584,8 @@ def get_header_version():
return levent._EVENT_VERSION return levent._EVENT_VERSION
def set_exc_info(object typ, object value, object tb): def set_exc_info(object value):
cdef object typ
cdef PyThreadState* tstate = PyThreadState_GET() cdef PyThreadState* tstate = PyThreadState_GET()
if tstate.exc_type != NULL: if tstate.exc_type != NULL:
Py_DECREF(<object>tstate.exc_type) Py_DECREF(<object>tstate.exc_type)
...@@ -592,13 +593,16 @@ def set_exc_info(object typ, object value, object tb): ...@@ -592,13 +593,16 @@ def set_exc_info(object typ, object value, object tb):
Py_DECREF(<object>tstate.exc_value) Py_DECREF(<object>tstate.exc_value)
if tstate.exc_traceback != NULL: if tstate.exc_traceback != NULL:
Py_DECREF(<object>tstate.exc_traceback) Py_DECREF(<object>tstate.exc_traceback)
Py_INCREF(typ) if value is None:
Py_INCREF(value) tstate.exc_type = NULL
Py_INCREF(tb) tstate.exc_value = NULL
tstate.exc_type = <void*>typ else:
tstate.exc_value = <void *>value typ = type(value)
tstate.exc_traceback = <void *>tb Py_INCREF(typ)
Py_INCREF(value)
tstate.exc_type = <void*>typ
tstate.exc_value = <void *>value
tstate.exc_traceback = NULL
#include "evdns.pxi" #include "evdns.pxi"
include "evbuffer.pxi" include "evbuffer.pxi"
......
...@@ -169,7 +169,7 @@ class Hub(greenlet): ...@@ -169,7 +169,7 @@ class Hub(greenlet):
def switch(self): def switch(self):
cur = getcurrent() cur = getcurrent()
assert cur is not self, 'Impossible to call blocking function in the event loop callback' assert cur is not self, 'Impossible to call blocking function in the event loop callback'
exc_info = sys.exc_info() exception = sys.exc_info()[1]
try: try:
switch_out = getattr(cur, 'switch_out', None) switch_out = getattr(cur, 'switch_out', None)
if switch_out is not None: if switch_out is not None:
...@@ -180,7 +180,7 @@ class Hub(greenlet): ...@@ -180,7 +180,7 @@ class Hub(greenlet):
sys.exc_clear() sys.exc_clear()
return greenlet.switch(self) return greenlet.switch(self)
finally: finally:
core.set_exc_info(*exc_info) core.set_exc_info(exception)
def run(self): def run(self):
global _threadlocal global _threadlocal
......
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