Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4b9b936

Browse files
committed
Don't decref exc too soon
1 parent c4c2580 commit 4b9b936

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

Objects/exceptions.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2685,7 +2685,6 @@ _PyErr_TrySetFromCause(const char *format, ...)
26852685
* state potentially stored on OSError instances.
26862686
*/
26872687

2688-
Py_DECREF(exc);
26892688
Py_XDECREF(tb);
26902689

26912690
#ifdef HAVE_STDARG_PROTOTYPES
@@ -2696,12 +2695,14 @@ _PyErr_TrySetFromCause(const char *format, ...)
26962695
msg_prefix = PyUnicode_FromFormatV(format, vargs);
26972696
va_end(vargs);
26982697
if (msg_prefix == NULL) {
2698+
Py_DECREF(exc);
26992699
Py_DECREF(val);
27002700
return NULL;
27012701
}
27022702

27032703
PyErr_Format(exc, "%U (%s: %S)",
27042704
msg_prefix, Py_TYPE(val)->tp_name, val);
2705+
Py_DECREF(exc);
27052706
Py_DECREF(msg_prefix);
27062707
PyErr_Fetch(&new_exc, &new_val, &new_tb);
27072708
PyErr_NormalizeException(&new_exc, &new_val, &new_tb);

0 commit comments

Comments
 (0)