Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix a ref count issue in PythonException
  • Loading branch information
BadSingleton committed Feb 26, 2021
commit ee30c94a5814150fb94d0892f5d909d102dc7b55
9 changes: 9 additions & 0 deletions src/runtime/pythonexception.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,16 @@ public void Normalize()
{
if (Exceptions.ErrorOccurred()) throw new InvalidOperationException("Cannot normalize when an error is set");
// If an error is set and this PythonException is unnormalized, the error will be cleared and the PythonException will be replaced by a different error.
IntPtr oldValue = _pyValue;
Runtime.PyErr_NormalizeException(ref _pyType, ref _pyValue, ref _pyTB);

if (_pyValue != oldValue)
{
// we own the reference to _pyValue, so make adjustments if it changed.
// Disown old, own new
Runtime.XDecref(oldValue);
Runtime.XIncref(_pyValue);
}
}
finally
{
Expand Down