Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leaks in TInvertedLuminanceSource when hints contains ZXing.DecodeHintType.ENABLE_INVERSION and ZXing.DecodeHintType.TRY_HARDER #172

Open
JedrzejczykRobert opened this issue Jun 8, 2024 · 0 comments

Comments

@JedrzejczykRobert
Copy link

In functions: crop, rotate

Self.delegate.crop(left, top, width, height)
Self.delegate.rotateCounterClockwise
Self.delegate.rotateCounterClockwise4

returns new instance of TLuminanceSource, it should be stored and released in TInvertedLuminanceSource.Destructor;

suggested changes:

constructor TInvertedLuminanceSource.Create(delegate: TLuminanceSource; ownDelegate : Boolean = FALSE);
begin
  inherited Create(delegate.Width, delegate.Height);
  Self.delegate := delegate;
  Self.ownDelegate := ownDelegate; // new property
end;

destructor TInvertedLuminanceSource.Destroy;
begin
  if Self.ownDelegate then
  begin
    FreeAndNil(Self.delegate);
  end;
  inherited;
end;

function TInvertedLuminanceSource.crop(const left, top, width, height: Integer): TLuminanceSource;
begin
  Result := TInvertedLuminanceSource.Create(
    Self.delegate.crop(left, top, width, height),
    TRUE);
end;

function TInvertedLuminanceSource.rotateCounterClockwise(): TLuminanceSource;
begin
  Result := TInvertedLuminanceSource.Create(
    Self.delegate.rotateCounterClockwise,
    TRUE);
end;

function TInvertedLuminanceSource.rotateCounterClockwise45(): TLuminanceSource;
begin
  Result := TInvertedLuminanceSource.Create(
    Self.delegate.rotateCounterClockwise45,
    TRUE);
end;

// should return new instance like TBaseLuminanceSource.Invert()
// not optimal, but consistent with the crop and rotate functions
function TInvertedLuminanceSource.invert: TLuminanceSource;
begin
  Result := TInvertedLuminanceSource.Create(SELF);
end;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant