Skip to content

Commit abce40a

Browse files
authored
Fix a memory leak
1 parent 8ab64d7 commit abce40a

File tree

4 files changed

+15
-21
lines changed

4 files changed

+15
-21
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
OPT=-Os -Wall
2-
CFLAGS=-fno-ident -fno-stack-check -fno-stack-protector
3-
LDFLAGS=-L. -nostartfiles -nostdlib -lucrt -luser32 -lkernel32 -Wl,--exclude-all-symbols,--enable-stdcall-fixup,--dynamicbase,--nxcompat,--subsystem,windows:6.0
2+
CFLAGS=-fno-ident
3+
LDFLAGS=-L. -nostartfiles -nostdlib -lkernel32 -lshlwapi -Wl,--exclude-all-symbols,--enable-stdcall-fixup,--dynamicbase,--nxcompat,--subsystem,windows:6.0
44

55
PREFIX32=C:/mingw32/bin/
66
PREFIX64=C:/mingw64/bin/

sppc.c

+8-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#define _WIN32_WINNT _WIN32_WINNT_WIN10
22
#include <windows.h>
3+
#include <shlwapi.h>
34

45
typedef GUID SLID;
56
typedef void *HSLC;
@@ -49,27 +50,20 @@ BOOL APIENTRY WINAPI dll_main(
4950
}
5051

5152
BOOL check_for_grace(HSLC hSLC, SLID *pProductSkuId) {
52-
PBYTE *pBuffer = malloc(4096);
53-
UINT cbSize = 4096;
53+
PBYTE pBuffer = 0;
54+
UINT cbSize = 0;
5455

55-
if(SLGetProductSkuInformation(
56-
hSLC,
57-
pProductSkuId,
58-
L"Name",
59-
NULL,
60-
&cbSize,
61-
pBuffer
62-
) != S_OK) {
63-
free(pBuffer);
56+
if(SLGetProductSkuInformation(hSLC, pProductSkuId, L"Name", NULL, &cbSize, &pBuffer) != S_OK) {
57+
LocalFree(pBuffer);
6458
return FALSE;
6559
}
6660

67-
if(wcsstr((PWSTR)*pBuffer, L"Grace") != NULL) {
68-
free(pBuffer);
61+
if(StrStrNIW((PWSTR)pBuffer, L"Grace", cbSize) != NULL) {
62+
LocalFree(pBuffer);
6963
return TRUE;
7064
}
7165

72-
free(pBuffer);
66+
LocalFree(pBuffer);
7367
return FALSE;
7468
}
7569

sppc.rc

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
1 VERSIONINFO
2-
FILEVERSION 0,2,0,0
3-
PRODUCTVERSION 0,2,0,0
2+
FILEVERSION 0,3,0,0
3+
PRODUCTVERSION 0,3,0,0
44
FILEOS 0x40004L
55
FILETYPE 0x2L
66
BEGIN
@@ -10,12 +10,12 @@ BEGIN
1010
BEGIN
1111
VALUE "CompanyName", "Anomalous Software Deterioration Corporation"
1212
VALUE "FileDescription", "ohook SPPC"
13-
VALUE "FileVersion", "0.2.0.0"
13+
VALUE "FileVersion", "0.3.0.0"
1414
VALUE "InternalName", "sppc"
1515
VALUE "LegalCopyright", "© 2023 Anomalous Software Deterioration Corporation"
1616
VALUE "OriginalFilename", "sppc.dll"
1717
VALUE "ProductName", "ohook"
18-
VALUE "ProductVersion", "0.2.0.0"
18+
VALUE "ProductVersion", "0.3.0.0"
1919
END
2020
END
2121

sppcs32.def

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
LIBRARY sppcs.dll
22
EXPORTS
33
SLGetLicensingStatusInformation@24
4-
SLGetProductSkuInformation@24
4+
SLGetProductSkuInformation@24

0 commit comments

Comments
 (0)