X Tutup
Skip to content

Commit 58bcdf0

Browse files
denfromufatonyroberts
authored andcommitted
Fix memory leak converting floats in converter.cs.
Fixes pythonnet#146
1 parent 559ebd4 commit 58bcdf0

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/runtime/converter.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,10 +578,10 @@ static bool ToPrimitive(IntPtr value, Type obType, out Object result,
578578
goto type_error;
579579
}
580580
ival = Runtime.PyInt_AsLong(op);
581+
Runtime.Decref(op);
581582
if (ival > Char.MaxValue || ival < Char.MinValue) {
582583
goto overflow;
583584
}
584-
Runtime.Decref(op);
585585
result = (char)ival;
586586
return true;
587587

@@ -644,14 +644,16 @@ static bool ToPrimitive(IntPtr value, Type obType, out Object result,
644644
goto type_error;
645645
}
646646
uint ui = (uint)Runtime.PyLong_AsUnsignedLong(op);
647-
Runtime.Decref(op);
647+
648648
if (Exceptions.ErrorOccurred()) {
649+
Runtime.Decref(op);
649650
goto overflow;
650651
}
651652

652653
IntPtr check = Runtime.PyLong_FromUnsignedLong(ui);
653654
int err = Runtime.PyObject_Compare(check, op);
654655
Runtime.Decref(check);
656+
Runtime.Decref(op);
655657
if (0 != err || Exceptions.ErrorOccurred()) {
656658
goto overflow;
657659
}
@@ -684,7 +686,8 @@ static bool ToPrimitive(IntPtr value, Type obType, out Object result,
684686
}
685687
goto type_error;
686688
}
687-
double dd = Runtime.PyFloat_AsDouble(value);
689+
double dd = Runtime.PyFloat_AsDouble(op);
690+
Runtime.Decref(op);
688691
if (dd > Single.MaxValue || dd < Single.MinValue) {
689692
goto overflow;
690693
}

0 commit comments

Comments
 (0)
X Tutup