8000 Fix exception refcnt by BadSingleton · Pull Request #1402 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

Fix exception refcnt #1402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
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
0