Skip to content
Merged
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
fix leak
  • Loading branch information
koubaa committed Oct 16, 2019
commit ff5d96c1c888f6f432689ecfe9190473955eb7c7
5 changes: 4 additions & 1 deletion src/runtime/classbase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,10 @@ public static IntPtr tp_repr(IntPtr ob)
IntPtr args = Runtime.PyTuple_New(1);
Runtime.PyTuple_SetItem(args, 0, ob);
IntPtr reprFunc = Runtime.PyObject_GetAttrString(Runtime.PyBaseObjectType, "__repr__");
return Runtime.PyObject_Call(reprFunc, args, IntPtr.Zero);
var output = Runtime.PyObject_Call(reprFunc, args, IntPtr.Zero);
Runtime.XDecref(args);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Decreasing args reference count actually decreases ob reference count, which marks it as garbage for the GC!
After a while GC frees the object which causes the program to crash if the object is used again.
One fix for this can be adding the line:
Runtime.XIncref(ob);
at line 269 (before setting ob to the tuple's first argument).

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.

Thanks a lot for catching this. Would you prepare a small PR?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Done
1160

Runtime.XDecref(reprFunc);
return output;
}
catch (Exception e)
{
Expand Down