Incorrect try/finally block in TROWinHttpWorker.Callback

Hi,

IMO, the code below incorrectly implements the try/finally concept for both aResponseStream and aRequestStream.

procedure TROWinHttpWorker.Callback(Caller: TROThreadPool; aThread: TThread);
var
  ...
  aRequestStream: TROBinaryMemoryStream;
  aResponseStream: TROBinaryMemoryStream;
begin
  aRequestStream := TROBinaryMemoryStream.Create;
  aRequestStream.Write(...
  try
    ...
  finally
    FreeOrDisposeOf(aRequestStream);
    FreeOrDisposeOf(aResponseStream);
  end;
end;

A possible solution could be

procedure TROWinHttpWorker.Callback(Caller: TROThreadPool; aThread: TThread);
var
  ...
  aRequestStream: TROBinaryMemoryStream;
  aResponseStream: TROBinaryMemoryStream;
begin
  aResponseStream := nil;
  aRequestStream := TROBinaryMemoryStream.Create;
  try
    aRequestStream.Write(...
    ...
  finally
    FreeOrDisposeOf(aRequestStream);
    FreeOrDisposeOf(aResponseStream);
  end;
end;

Best regards
Alexander

Hi,

main reason was to correctly handle possible errors in fOwner.ProcessRequest, but you are right, I’ll update code.

Thanks, logged as bugs://85813

bugs://85813 got closed with status fixed.