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

Skip to content

Commit 399ae54

Browse files
committed
do not dispose object, that might have been just decoded succesfully, as the decoded object might store a reference to the original PyObject
1 parent 44bfec2 commit 399ae54

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/runtime/converterextensions.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,16 @@ static Converter.TryConvertFromPythonDelegate GetDecoder(IntPtr sourceType, Type
137137

138138
bool TryDecode(IntPtr pyHandle, out object result)
139139
{
140-
using (var pyObj = new PyObject(Runtime.SelfIncRef(pyHandle)))
140+
var pyObj = new PyObject(Runtime.SelfIncRef(pyHandle));
141+
var @params = new object[] { pyObj, null };
142+
bool success = (bool)decode.Invoke(decoder, @params);
143+
if (!success)
141144
{
142-
var @params = new object[] { pyObj, null };
143-
bool success = (bool)decode.Invoke(decoder, @params);
144-
result = @params[1];
145-
return success;
145+
pyObj.Dispose();
146146
}
147+
148+
result = @params[1];
149+
return success;
147150
}
148151

149152
return TryDecode;

0 commit comments

Comments
 (0)