Fix handle leak, dangling handle, and UnlockFile bugs

- Fix cleanup block checking hint instead of hint2 before closing
- Fix hint2 not being set to NULL after InternetCloseHandle
- Replace UnlockFile(NULL params) with UnlockFileEx matching LockFileEx params
This commit is contained in:
Andy | ZephrFish 2026-04-05 13:12:38 +01:00
parent 48f6a48094
commit 858af55117
No known key found for this signature in database

View file

@ -685,7 +685,7 @@ UpdateFiles* GetUpdateFiles(int* filecount = NULL)
InternetCloseHandle(hint); InternetCloseHandle(hint);
hint = NULL; hint = NULL;
InternetCloseHandle(hint2); InternetCloseHandle(hint2);
hint = NULL; hint2 = NULL;
printf("Done.\n"); printf("Done.\n");
mappedbuff = GetCabFileFromBuff((PIMAGE_DOS_HEADER)exebuff, sz, &ressz); mappedbuff = GetCabFileFromBuff((PIMAGE_DOS_HEADER)exebuff, sz, &ressz);
@ -3318,7 +3318,7 @@ int wmain(int argc, wchar_t* argv[])
goto cleanup; goto cleanup;
} }
UnlockFile(hleakedfile, NULL, NULL, NULL, NULL); UnlockFileEx(hleakedfile, 0, _filesz.LowPart, _filesz.HighPart, &ovd2);
filelocked = false; filelocked = false;
CloseHandle(hleakedfile); CloseHandle(hleakedfile);
printf("Read %d bytes\n", __readsz); printf("Read %d bytes\n", __readsz);
@ -3377,7 +3377,7 @@ cleanup:
if(hint) if(hint)
InternetCloseHandle(hint); InternetCloseHandle(hint);
if(hint) if(hint2)
InternetCloseHandle(hint2); InternetCloseHandle(hint2);
if (exebuff) if (exebuff)
free(exebuff); free(exebuff);
@ -3407,7 +3407,7 @@ cleanup:
if (hleakedfile) if (hleakedfile)
{ {
if (filelocked) if (filelocked)
UnlockFile(hleakedfile, NULL, NULL, NULL, NULL); UnlockFileEx(hleakedfile, 0, _filesz.LowPart, _filesz.HighPart, &ovd2);
CloseHandle(hleakedfile); CloseHandle(hleakedfile);
} }
if (leakedfilebuff) if (leakedfilebuff)