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

Skip to content

Commit 50a3822

Browse files
committed
corrected reference counting in Codecs
1 parent ec98209 commit 50a3822

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/runtime/converter.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,10 @@ internal static IntPtr ToPython(object value, Type type)
138138
if (Type.GetTypeCode(type) == TypeCode.Object && value.GetType() != typeof(object)) {
139139
var encoded = PyObjectConversions.TryEncode(value, type);
140140
if (encoded != null) {
141-
Runtime.XIncref(encoded.Handle);
142-
return encoded.Handle;
141+
result = encoded.Handle;
142+
Runtime.XIncref(result);
143+
encoded.Dispose();
144+
return result;
143145
}
144146
}
145147

src/runtime/converterextensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ internal static bool TryDecode(IntPtr pyHandle, IntPtr pyType, Type targetType,
124124
static Converter.TryConvertFromPythonDelegate GetDecoder(IntPtr sourceType, Type targetType)
125125
{
126126
IPyObjectDecoder decoder;
127-
using (var pyType = new PyObject(sourceType))
127+
using (var pyType = new PyObject(Runtime.SelfIncRef(sourceType)))
128128
{
129129
lock (decoders)
130130
{

0 commit comments

Comments
 (0)