Skip to content

Commit 53265f6

Browse files
committed
Users: fix memleaks (Windows)
1 parent f245492 commit 53265f6

File tree

3 files changed

+48
-22
lines changed

3 files changed

+48
-22
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ if(APPLE)
654654
PRIVATE "-weak_framework MediaRemote -F /System/Library/PrivateFrameworks"
655655
)
656656
elseif(WIN32)
657+
target_compile_definitions(libfastfetch PRIVATE -D_WIN32_WINNT=0x0601)
657658
target_link_libraries(libfastfetch
658659
PRIVATE "dwmapi"
659660
PRIVATE "gdi32"

src/detection/users/users_windows.c

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,7 @@
22
#include "util/windows/unicode.h"
33

44
#include <wtsapi32.h>
5-
6-
//at the time of writing, <wtsapi32.h> of MinGW doesn't have the definition of WTSEnumerateSessionsExW
7-
typedef struct _WTS_SESSION_INFO_1W {
8-
DWORD ExecEnvId;
9-
WTS_CONNECTSTATE_CLASS State;
10-
DWORD SessionId;
11-
LPWSTR pSessionName;
12-
LPWSTR pHostName;
13-
LPWSTR pUserName;
14-
LPWSTR pDomainName;
15-
LPWSTR pFarmName;
16-
} WTS_SESSION_INFO_1W, * PWTS_SESSION_INFO_1W;
17-
18-
BOOL
19-
WINAPI
20-
WTSEnumerateSessionsExW(
21-
HANDLE hServer,
22-
DWORD* pLevel,
23-
DWORD Filter,
24-
PWTS_SESSION_INFO_1W* ppSessionInfo,
25-
DWORD* pCount);
5+
#include "wtsapi32_extend.h"
266

277
void ffDetectUsers(FFlist* users, FFstrbuf* error)
288
{
@@ -48,7 +28,7 @@ void ffDetectUsers(FFlist* users, FFstrbuf* error)
4828
ffStrbufInitF((FFstrbuf*)ffListAdd(users), "%s\\%s", domainName.chars, userName.chars);
4929
}
5030

51-
WTSFreeMemory(sessionInfo);
31+
WTSFreeMemoryExW(WTSTypeSessionInfoLevel1, sessionInfo, 1);
5232

5333
if(users->length == 0)
5434
ffStrbufAppendS(error, "Unable to detect users");
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#pragma once
2+
3+
//at the time of writing, <wtsapi32.h> of MinGW doesn't have the definition of WTSEnumerateSessionsExW and friends
4+
5+
#if (_WIN32_WINNT >= 0x0601)
6+
7+
typedef struct _WTS_SESSION_INFO_1A {
8+
DWORD ExecEnvId;
9+
WTS_CONNECTSTATE_CLASS State;
10+
DWORD SessionId;
11+
LPSTR pSessionName;
12+
LPSTR pHostName;
13+
LPSTR pUserName;
14+
LPSTR pDomainName;
15+
LPSTR pFarmName;
16+
} WTS_SESSION_INFO_1A, *PWTS_SESSION_INFO_1A;
17+
18+
typedef struct _WTS_SESSION_INFO_1W {
19+
DWORD ExecEnvId;
20+
WTS_CONNECTSTATE_CLASS State;
21+
DWORD SessionId;
22+
LPWSTR pSessionName;
23+
LPWSTR pHostName;
24+
LPWSTR pUserName;
25+
LPWSTR pDomainName;
26+
LPWSTR pFarmName;
27+
} WTS_SESSION_INFO_1W, * PWTS_SESSION_INFO_1W;
28+
29+
#define WTS_SESSION_INFO_1 __MINGW_NAME_AW(WTS_SESSION_INFO_1)
30+
#define PWTS_SESSION_INFO_1 __MINGW_NAME_AW(PWTS_SESSION_INFO_1)
31+
32+
WINBOOL WINAPI WTSEnumerateSessionsExA(HANDLE hServer,DWORD* pLevel,DWORD Filter,PWTS_SESSION_INFO_1A* ppSessionInfo,DWORD* pCount);
33+
WINBOOL WINAPI WTSEnumerateSessionsExW(HANDLE hServer,DWORD* pLevel,DWORD Filter,PWTS_SESSION_INFO_1W* ppSessionInfo,DWORD* pCount);
34+
#define WTSEnumerateSessionsEx __MINGW_NAME_AW(WTSEnumerateSessionsEx)
35+
36+
typedef enum _WTS_TYPE_CLASS {
37+
WTSTypeProcessInfoLevel0,
38+
WTSTypeProcessInfoLevel1,
39+
WTSTypeSessionInfoLevel1
40+
} WTS_TYPE_CLASS;
41+
BOOL WTSFreeMemoryExA(WTS_TYPE_CLASS WTSTypeClass,PVOID pMemory,ULONG NumberOfEntries);
42+
BOOL WTSFreeMemoryExW(WTS_TYPE_CLASS WTSTypeClass,PVOID pMemory,ULONG NumberOfEntries);
43+
#define WTSFreeMemoryEx __MINGW_NAME_AW(WTSFreeMemoryEx)
44+
45+
#endif /*(_WIN32_WINNT >= 0x0601)*/

0 commit comments

Comments
 (0)