Skip to content

Commit 2aa9e28

Browse files
authored
Merge pull request #3413 from carenas/headless
headless: avoid leaking handles and other minor cleanup
2 parents 82a7ae1 + e3c2451 commit 2aa9e28

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

compat/win32/headless.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,17 @@ static int extend_path(wchar_t *dir, size_t dir_len)
4444
return 1;
4545
}
4646

47-
int WINAPI wWinMain(HINSTANCE instance, HINSTANCE previous_instance,
48-
wchar_t *command_line, int show)
47+
int WINAPI wWinMain(_In_ HINSTANCE instance,
48+
_In_opt_ HINSTANCE previous_instance,
49+
_In_ LPWSTR command_line, _In_ int show)
4950
{
5051
wchar_t git_command_line[32768];
5152
size_t size = sizeof(git_command_line) / sizeof(wchar_t);
5253
const wchar_t *needs_quotes = L"";
5354
int slash = 0, i;
5455

5556
STARTUPINFO startup_info = {
57+
.cb = sizeof(STARTUPINFO),
5658
.dwFlags = STARTF_USESHOWWINDOW,
5759
.wShowWindow = SW_HIDE,
5860
};
@@ -68,7 +70,7 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE previous_instance,
6870
else if (_wpgmptr[i] == L'\\')
6971
slash = i;
7072

71-
if (slash + 11 >= sizeof(git_command_line) / sizeof(wchar_t))
73+
if (slash >= size - 11)
7274
return 127; /* Too long path */
7375

7476
/* If it is in Git's exec path, add the bin/ directory to the PATH */
@@ -88,8 +90,6 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE previous_instance,
8890
return 127;
8991
}
9092

91-
startup_info.cb = sizeof(STARTUPINFO);
92-
9393
startup_info.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
9494
startup_info.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
9595
startup_info.hStdError = GetStdHandle(STD_ERROR_HANDLE);
@@ -105,10 +105,11 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE previous_instance,
105105
&startup_info, &process_info))
106106
return 129; /* could not start */
107107
WaitForSingleObject(process_info.hProcess, INFINITE);
108-
if (!GetExitCodeProcess(process_info.hProcess, &exit_code)) {
109-
CloseHandle(process_info.hProcess);
110-
return 130; /* Could not determine exit code? */
111-
}
108+
if (!GetExitCodeProcess(process_info.hProcess, &exit_code))
109+
exit_code = 130; /* Could not determine exit code? */
110+
111+
CloseHandle(process_info.hProcess);
112+
CloseHandle(process_info.hThread);
112113

113114
return (int)exit_code;
114115
}

0 commit comments

Comments
 (0)