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
Prev Previous commit
Next Next commit
improve ref counting
  • Loading branch information
koubaa committed Dec 3, 2019
commit 96fd89692a7ce74213e08fa6e70163f1dcc4530d
8 changes: 2 additions & 6 deletions src/runtime/converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -941,22 +941,18 @@ private static bool ToAction(IntPtr value, Type obType, out object result, bool
if (setError) {
SetConversionError(value, obType);
}
obj.Dispose();
return false;
}

Action action = () => {
PyObject py_action = new PyObject(value);
var py_args = new PyObject[0];
var py_result = py_action.Invoke(py_args);

//Discard the result since this is being converted to an Action
py_result.Dispose();
py_action.Dispose();
Runtime.XDecref(value);
};
Comment on lines +948 to +962
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The object pointed to by value can be collected between the construction of this action, and the moment it is invoked. It would lead to a memory corruption.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had forgotten to push the latest change set, please check again


Runtime.XIncref(value);
result = action;
obj.Dispose();
return true;
}

Expand Down