You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2020/02/12 21:48:15 UTC
[thrift] branch master updated: THRIFT-5088 Memory leak in
TWinHttpTransport Client: Delphi Patch: Jens Geyer
This is an automated email from the ASF dual-hosted git repository.
jensg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git
The following commit(s) were added to refs/heads/master by this push:
new b012318 THRIFT-5088 Memory leak in TWinHttpTransport Client: Delphi Patch: Jens Geyer
b012318 is described below
commit b012318fc8f1d3de4c64514d5d32cb424952d905
Author: Jens Geyer <je...@apache.org>
AuthorDate: Wed Feb 12 12:16:19 2020 +0100
THRIFT-5088 Memory leak in TWinHttpTransport
Client: Delphi
Patch: Jens Geyer
---
lib/delphi/src/Thrift.Transport.WinHTTP.pas | 5 +++--
lib/delphi/src/Thrift.Transport.pas | 2 +-
lib/delphi/src/Thrift.WinHTTP.pas | 22 +++++++++++-----------
3 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/lib/delphi/src/Thrift.Transport.WinHTTP.pas b/lib/delphi/src/Thrift.Transport.WinHTTP.pas
index 7a1b48f..5794b1c 100644
--- a/lib/delphi/src/Thrift.Transport.WinHTTP.pas
+++ b/lib/delphi/src/Thrift.Transport.WinHTTP.pas
@@ -309,7 +309,7 @@ var
http : IWinHTTPRequest;
pData : PByte;
len : Integer;
- error : Cardinal;
+ error, dwSize : Cardinal;
sMsg : string;
begin
http := CreateRequest;
@@ -334,7 +334,8 @@ begin
end;
FInputStream := THTTPResponseStream.Create( http);
- UpdateKnownMessageSize( http.QueryTotalResponseSize);
+ if http.QueryTotalResponseSize( dwSize) // FALSE indicates "no info available"
+ then UpdateKnownMessageSize( dwSize);
end;
procedure TWinHTTPClientImpl.Write( const pBuf : Pointer; off, len : Integer);
diff --git a/lib/delphi/src/Thrift.Transport.pas b/lib/delphi/src/Thrift.Transport.pas
index af62548..1b8300c 100644
--- a/lib/delphi/src/Thrift.Transport.pas
+++ b/lib/delphi/src/Thrift.Transport.pas
@@ -579,7 +579,7 @@ begin
// update only: message size can shrink, but not grow
ASSERT( KnownMessageSize <= MaxMessageSize);
if newSize > KnownMessageSize
- then TTransportExceptionEndOfFile.Create('MaxMessageSize reached');
+ then raise TTransportExceptionEndOfFile.Create('MaxMessageSize reached');
FKnownMessageSize := newSize;
FRemainingMessageSize := newSize;
diff --git a/lib/delphi/src/Thrift.WinHTTP.pas b/lib/delphi/src/Thrift.WinHTTP.pas
index d060066..5c07193 100644
--- a/lib/delphi/src/Thrift.WinHTTP.pas
+++ b/lib/delphi/src/Thrift.WinHTTP.pas
@@ -576,7 +576,7 @@ type
IWinHTTPConnection = interface;
IWinHTTPRequest = interface
- ['{7A8E7255-5440-4621-A8A8-1E9FFAA6D6FA}']
+ ['{7AE6F63F-49B6-436B-8AAB-159E58EB900A}']
function Handle : HINTERNET;
function Connection : IWinHTTPConnection;
function AddRequestHeader( const aHeader : string; const addflag : DWORD = WINHTTP_ADDREQ_FLAG_ADD) : Boolean;
@@ -589,7 +589,7 @@ type
function ReadData( const dwRead : DWORD) : TBytes; overload;
function ReadData( const pBuf : Pointer; const dwRead : DWORD) : DWORD; overload;
function QueryDataAvailable : DWORD;
- function QueryTotalResponseSize : DWORD;
+ function QueryTotalResponseSize( out dwSize : DWORD) : Boolean;
end;
IWinHTTPConnection = interface
@@ -709,7 +709,7 @@ type
function ReadData( const dwRead : DWORD) : TBytes; overload;
function ReadData( const pBuf : Pointer; const dwRead : DWORD) : DWORD; overload;
function QueryDataAvailable : DWORD;
- function QueryTotalResponseSize : DWORD;
+ function QueryTotalResponseSize( out dwSize : DWORD) : Boolean;
public
constructor Create( const aConnection : IWinHTTPConnection;
@@ -1212,20 +1212,20 @@ begin
end;
-function TWinHTTPRequestImpl.QueryTotalResponseSize : DWORD;
+function TWinHTTPRequestImpl.QueryTotalResponseSize( out dwSize : DWORD) : Boolean;
var dwBytes, dwError, dwIndex : DWORD;
begin
dwBytes := SizeOf( result);
dwIndex := DWORD( WINHTTP_NO_HEADER_INDEX);
- if not WinHttpQueryHeaders( FHandle,
- WINHTTP_QUERY_CONTENT_LENGTH or WINHTTP_QUERY_FLAG_NUMBER,
- WINHTTP_HEADER_NAME_BY_INDEX,
- @result, dwBytes,
- dwIndex)
- then begin
+ result := WinHttpQueryHeaders( FHandle,
+ WINHTTP_QUERY_CONTENT_LENGTH or WINHTTP_QUERY_FLAG_NUMBER,
+ WINHTTP_HEADER_NAME_BY_INDEX,
+ @dwSize, dwBytes,
+ dwIndex);
+ if not result then begin
+ dwSize := MAXINT; // we don't know, just return something useful
dwError := GetLastError;
if dwError <> ERROR_WINHTTP_HEADER_NOT_FOUND then ASSERT(FALSE); // anything else would be an real error
- result := MAXINT; // we don't know
end;
end;