View Issue Details

IDProjectCategoryView StatusLast Update
0038020FPCRTLpublic2020-11-04 12:08
ReporterSergey Larin Assigned ToSven Barth  
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionfixed 
Fixed in Version3.3.1 
Summary0038020: Using GetModuleHandle instead of LoadLibrary when getting the GetTickCount64 address
DescriptionWhen getting the address of the GetTickCount64 function, GetModuleHandle('kernel32.dll') is used, not LoadLibrary('kernel32.dll').
It is generally wrong to use LoadLibrary('kernel32.dll') without FreeLibrary('kernel32.dll').
You can use GetModuleHandle('kernel32.dll') because at the time of calling GetTickCount64 from SysUtils, the kernel32.dll library is guaranteed to be loaded.
Tagspatch, rtl
Fixed in Revision47274
FPCOldBugId
FPCTarget-
Attached Files

Activities

Sergey Larin

2020-11-01 16:55

reporter  

gettickcount64-win-loadlibrary-fix.patch (852 bytes)   
diff --git a/rtl/win/sysutils.pp b/rtl/win/sysutils.pp
index 3c1f8eb791..cd617af960 100644
--- a/rtl/win/sysutils.pp
+++ b/rtl/win/sysutils.pp
@@ -847,19 +847,13 @@ var
 {$ENDIF}
 
 function GetTickCount64: QWord;
-{$IFNDEF WINCE}
-var
-  lib: THandle;
-{$ENDIF}
 begin
 {$IFNDEF WINCE}
+  if Assigned(WinGetTickCount64) then
+    Exit(WinGetTickCount64());
   { on Vista and newer there is a GetTickCount64 implementation }
   if Win32MajorVersion >= 6 then begin
-    if not Assigned(WinGetTickCount64) then begin
-      lib := LoadLibrary('kernel32.dll');
-      WinGetTickCount64 := TGetTickCount64(
-                             GetProcAddress(lib, 'GetTickCount64'));
-    end;
+    WinGetTickCount64 := TGetTickCount64(GetProcAddress(GetModuleHandle('kernel32.dll'), 'GetTickCount64'));
     Result := WinGetTickCount64();
   end else
 {$ENDIF}

Sven Barth

2020-11-01 20:41

manager   ~0126688

Thank you for the patch. Please test and close if okay.

Issue History

Date Modified Username Field Change
2020-11-01 16:55 Sergey Larin New Issue
2020-11-01 16:55 Sergey Larin File Added: gettickcount64-win-loadlibrary-fix.patch
2020-11-01 16:55 Sergey Larin Tag Attached: rtl
2020-11-01 16:55 Sergey Larin Tag Attached: patch
2020-11-01 20:41 Sven Barth Assigned To => Sven Barth
2020-11-01 20:41 Sven Barth Status new => resolved
2020-11-01 20:41 Sven Barth Resolution open => fixed
2020-11-01 20:41 Sven Barth Fixed in Version => 3.3.1
2020-11-01 20:41 Sven Barth Fixed in Revision => 47274
2020-11-01 20:41 Sven Barth FPCTarget => -
2020-11-01 20:41 Sven Barth Note Added: 0126688
2020-11-04 12:08 Sergey Larin Status resolved => closed