From 858af5511755069de14c67636d9d7ba1334c4f85 Mon Sep 17 00:00:00 2001 From: Andy | ZephrFish Date: Sun, 5 Apr 2026 13:12:38 +0100 Subject: [PATCH] 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 --- FunnyApp.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/FunnyApp.cpp b/FunnyApp.cpp index 35897e6..4760efa 100644 --- a/FunnyApp.cpp +++ b/FunnyApp.cpp @@ -685,7 +685,7 @@ UpdateFiles* GetUpdateFiles(int* filecount = NULL) InternetCloseHandle(hint); hint = NULL; InternetCloseHandle(hint2); - hint = NULL; + hint2 = NULL; printf("Done.\n"); mappedbuff = GetCabFileFromBuff((PIMAGE_DOS_HEADER)exebuff, sz, &ressz); @@ -3318,7 +3318,7 @@ int wmain(int argc, wchar_t* argv[]) goto cleanup; } - UnlockFile(hleakedfile, NULL, NULL, NULL, NULL); + UnlockFileEx(hleakedfile, 0, _filesz.LowPart, _filesz.HighPart, &ovd2); filelocked = false; CloseHandle(hleakedfile); printf("Read %d bytes\n", __readsz); @@ -3377,7 +3377,7 @@ cleanup: if(hint) InternetCloseHandle(hint); - if(hint) + if(hint2) InternetCloseHandle(hint2); if (exebuff) free(exebuff); @@ -3407,7 +3407,7 @@ cleanup: if (hleakedfile) { if (filelocked) - UnlockFile(hleakedfile, NULL, NULL, NULL, NULL); + UnlockFileEx(hleakedfile, 0, _filesz.LowPart, _filesz.HighPart, &ovd2); CloseHandle(hleakedfile); } if (leakedfilebuff)