- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 325
Closed
Labels
Description
Recently PythonEngine.pas was modified to include 'obj.Free' when Engine.PyErr_Occurred indicates an error. As a result, the newly created object will be destroyed twice as Engine.Py_DECREF(Result) will also call the destructor in PyObjectDestructor() (in this code 'obj' and 'Result' are pointing to the same object following 'obj := PythonToDelphi(Result)').
Here is the relevant code excerpt:
function  TPythonType.NewSubtypeInst( aType: PPyTypeObject; args, kwds : PPyObject) : PPyObject;
var
  obj : TPyObject;
begin
(..)
  if Assigned(Result) then
  begin
    obj := PythonToDelphi(Result);
    (..)
    if Engine.PyErr_Occurred <> nil then
    begin
      Engine.Py_DECREF(Result);
      Result := nil;
      obj.Free; // <- This statement is redundant and calls the destructor for the 2nd time
    end;
  end;
end;
My proposal is to remove the redundant/erroneous call to obj.Free above. Do you agree?
Alexey-TLennertP