Replace all malloc/free with LocalAlloc/LocalFree

This commit is contained in:
Adam Demasi 2024-09-17 00:56:34 +09:30
parent c20a9fab49
commit fe2399bae4
No known key found for this signature in database
GPG key ID: 5D3B26B3D58C7D91
5 changed files with 7 additions and 6 deletions

View file

@ -8,7 +8,7 @@ void __cdecl IsProcessRunning(HWND hwndParent, int string_size, TCHAR *variables
EXDLL_INIT();
g_hwndParent = hwndParent;
LPTSTR process = (LPTSTR)malloc(string_size * sizeof(TCHAR));
LPTSTR process = (LPTSTR)LocalAlloc(LPTR, string_size * sizeof(TCHAR));
popstring(process);
CharLowerBuffW(process, wcslen(process));
@ -17,5 +17,5 @@ void __cdecl IsProcessRunning(HWND hwndParent, int string_size, TCHAR *variables
wsprintf(buffer, L"%d", pid);
pushstring(buffer);
free(process);
LocalFree(process);
}

View file

@ -1,6 +1,7 @@
#pragma once
#include <windows.h>
#include "Registry.h"
static LPWSTR _installPath;

View file

@ -11,13 +11,13 @@ HRESULT GetRegistryString(HKEY key, LPCWSTR subkeyPath, LPCWSTR valueName, DWORD
if (data != NULL && size != NULL) {
DWORD length = 512 * sizeof(WCHAR);
LPWSTR buffer = (LPWSTR)malloc(length);
LPWSTR buffer = (LPWSTR)LocalAlloc(LPTR, length);
LSTATUS status;
do {
status = RegQueryValueEx(subkey, valueName, NULL, NULL, (BYTE *)buffer, &length);
if (status == ERROR_MORE_DATA) {
length += 256 * sizeof(WCHAR);
buffer = (LPWSTR)realloc(buffer, length);
buffer = (LPWSTR)LocalReAlloc(buffer, length, LMEM_MOVEABLE);
} else if (status != ERROR_SUCCESS) {
hr = HRESULT_FROM_WIN32(status);
goto end;

View file

@ -17,7 +17,7 @@ HRESULT GetOwnVersion(LPWSTR *version, LPDWORD size) {
return HRESULT_FROM_WIN32(GetLastError());
}
LPVOID verInfo = malloc(verInfoSize);
LPVOID verInfo = LocalAlloc(LPTR, verInfoSize);
if (!GetFileVersionInfo(filename, verHandle, verInfoSize, verInfo)) {
return HRESULT_FROM_WIN32(GetLastError());
}

View file

@ -35,6 +35,6 @@ static inline BOOL IsOSVersionOrEarlier(DWORD major, DWORD minor) {
HRESULT GetOwnVersion(LPWSTR *version, LPDWORD size);
static inline void GetOwnFileName(LPWSTR *filename, LPDWORD size) {
*filename = (LPWSTR)malloc(MAX_PATH);
*filename = (LPWSTR)LocalAlloc(LPTR, MAX_PATH);
*size = GetModuleFileName((HMODULE)&__ImageBase, *filename, MAX_PATH);
}