mirror of
https://github.com/pbatard/rufus.git
synced 2025-05-24 19:54:25 -04:00
[misc] fix various Coverity issues
* update DLL load/unload * fix resources not being freed and potentially unsafe calls * add extra checks
This commit is contained in:
parent
9aa308213d
commit
266599e6fd
12 changed files with 68 additions and 36 deletions
16
src/rufus.h
16
src/rufus.h
|
@ -400,11 +400,23 @@ extern void StrArrayDestroy(StrArray* arr);
|
|||
* pfFormatEx = (FormatEx_t) GetProcAddress(GetDLLHandle("fmifs"), "FormatEx");
|
||||
* to make it accessible.
|
||||
*/
|
||||
#define MAX_LIBRARY_HANDLES 32
|
||||
extern HMODULE OpenLibraryHandle[MAX_LIBRARY_HANDLES];
|
||||
extern uint16_t OpenLibraryHandleSize;
|
||||
#define OPEN_LIBRARIES_TRACKING_VARS HMODULE OpenLibraryHandle[MAX_LIBRARY_HANDLES]; uint16_t OpenLibraryHandleSize = 0
|
||||
#define OPEN_LIBRARIES_CLOSE_ALL while(OpenLibraryHandleSize > 0) FreeLibrary(OpenLibraryHandle[--OpenLibraryHandleSize])
|
||||
static __inline HMODULE GetDLLHandle(char* szDLLName)
|
||||
{
|
||||
HMODULE h = NULL;
|
||||
if ((h = GetModuleHandleA(szDLLName)) == NULL)
|
||||
h = LoadLibraryA(szDLLName);
|
||||
if ((h = GetModuleHandleA(szDLLName)) == NULL) {
|
||||
if (OpenLibraryHandleSize >= MAX_LIBRARY_HANDLES) {
|
||||
uprintf("Error: MAX_LIBRARY_HANDLES is too small\n");
|
||||
} else {
|
||||
h = LoadLibraryA(szDLLName);
|
||||
if (h != NULL)
|
||||
OpenLibraryHandle[OpenLibraryHandleSize++] = h;
|
||||
}
|
||||
}
|
||||
return h;
|
||||
}
|
||||
#define PF_DECL(proc) proc##_t pf##proc = NULL
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue