Skip to content

Commit 24ee877

Browse files
committed
TerminalShell: code refactoring
1 parent 7310b3e commit 24ee877

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

src/detection/terminalshell/terminalshell.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#ifdef _WIN32
77

8+
#include "util/mallocHelper.h"
9+
810
#include <winver.h>
911

1012
static bool getFileVersion(const char* exePath, FFstrbuf* version)
@@ -13,7 +15,7 @@ static bool getFileVersion(const char* exePath, FFstrbuf* version)
1315
DWORD size = GetFileVersionInfoSizeA(exePath, &handle);
1416
if(size > 0)
1517
{
16-
void* versionData = malloc(size);
18+
FF_AUTO_FREE void* versionData = malloc(size);
1719
if(GetFileVersionInfoA(exePath, handle, size, versionData))
1820
{
1921
VS_FIXEDFILEINFO* verInfo;
@@ -26,11 +28,9 @@ static bool getFileVersion(const char* exePath, FFstrbuf* version)
2628
(unsigned)(( verInfo->dwFileVersionLS >> 16 ) & 0xffff),
2729
(unsigned)(( verInfo->dwFileVersionLS >> 0 ) & 0xffff)
2830
);
29-
free(versionData);
3031
return true;
3132
}
3233
}
33-
free(versionData);
3434
}
3535

3636
return false;
@@ -195,11 +195,7 @@ FF_MAYBE_UNUSED static bool getTerminalVersionKonsole(FFstrbuf* exe, FFstrbuf* v
195195

196196
FF_MAYBE_UNUSED static bool getTerminalVersionFoot(FFstrbuf* exe, FFstrbuf* version)
197197
{
198-
if(ffProcessAppendStdOut(version, (char* const[]){
199-
exe->chars,
200-
"--version",
201-
NULL
202-
})) return false;
198+
if(!getExeVersionRaw(exe, version)) return false;
203199

204200
//foot version: 1.13.1 -pgo +ime -graphemes -assertions
205201
ffStrbufSubstrAfterFirstS(version, "version: ");
@@ -279,11 +275,7 @@ bool fftsGetTerminalVersion(FFstrbuf* processName, FF_MAYBE_UNUSED FFstrbuf* exe
279275
if(ffStrbufIgnCaseEqualS(processName, "kitty"))
280276
return getExeVersionGeneral(exe, version); //kitty 0.21.2 created by Kovid Goyal
281277

282-
if (ffStrbufIgnCaseEqualS(processName, "Tabby") && !ffProcessAppendStdOut(version, (char* const[]){
283-
exe->chars,
284-
"--version",
285-
NULL
286-
}))
278+
if (ffStrbufIgnCaseEqualS(processName, "Tabby") && getExeVersionRaw(exe, version))
287279
return true;
288280

289281
#endif

0 commit comments

Comments
 (0)