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? #7

Open
maxirobaina opened this issue May 4, 2013 · 1 comment
Open

Memory Leaks? #7

maxirobaina opened this issue May 4, 2013 · 1 comment

Comments

@maxirobaina
Copy link

Hi
I was reviewing some code and I can see several memory leaks that can happen.
I have not used FreePascal but I have used Delphi from almost 15 years and I can see thing like this: https://github.com/motaz/turbobird/blob/master/querywindow.pas#L693

For me It must to be like: (pay attention to try...finally block)

procedure TfmQueryWindow.tbCommitRetainingClick(Sender: TObject);
var
QT: TQueryThread;
begin
QT := TQueryThread.Create('commitret');
try
QT.Trans:= SqlTrans;
QT.Resume;
repeat
application.ProcessMessages;
until QT.fTerminated;

  if QT.Error then
    ShowMessage(QT.ErrorMsg)
  else
  begin
    // Call OnCommit procedure if assigned, it is used to refresh table management view
    if OnCommit <> nil then
      OnCommit(self);
    OnCommit:= nil;

  end;

finally
QT.Free;
end;
end;

I mean, the consuption of resources (objects, read files, etc) must be protected for a try...finally block. If anything fail inside this block, We need to ensure that the memory will be freed.

Let me know your opinion.

Regards.

Maxi.

@motaz
Copy link
Owner

motaz commented May 4, 2013

That's right, I've added try finally to commit, rollback procedures, but the code needs refactoring to make it easy to find memory leaks. Lazarus still has some issues regarding refactoring.

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

2 participants