From 4a14a7fc16fc8b63bbd9d65e3a627fc850178339 Mon Sep 17 00:00:00 2001 From: Peter Oberndorfer Date: Wed, 3 Aug 2011 21:36:10 +0200 Subject: [PATCH] do not leak process handles opened by fork_process/CreateProcess Every time a file/folder was selected in explorer 1 or 2 process handles were leaked when executing git to gathering information. [jes: squashed in non-win32 compile fixes by Heiko Voigt] Signed-off-by: Peter Oberndorfer Signed-off-by: Johannes Schindelin --- common/exec.c | 1 + common/systeminfo.h | 6 ++++++ explorer/systeminfo.c | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/common/exec.c b/common/exec.c index 9c3dcbd..9dc9cb0 100644 --- a/common/exec.c +++ b/common/exec.c @@ -125,6 +125,7 @@ int exec_program_v(const char *working_directory, working_directory, argv[0]); } } + close_process(pid); if (output) close(fdout[0]); diff --git a/common/systeminfo.h b/common/systeminfo.h index 62c9a7f..e04043b 100644 --- a/common/systeminfo.h +++ b/common/systeminfo.h @@ -21,4 +21,10 @@ pid_t fork_process(const char *cmd, const char **args, const char *wd); */ int wait_for_process(pid_t pid, int max_time, int *errcode); +#ifndef _WIN32 +#define close_process +#else +void close_process(pid_t pid); +#endif + #endif /* SYSTEMINFO_H */ diff --git a/explorer/systeminfo.c b/explorer/systeminfo.c index 69112d9..9f03df2 100644 --- a/explorer/systeminfo.c +++ b/explorer/systeminfo.c @@ -187,3 +187,8 @@ int wait_for_process(pid_t pid, int max_time, int *errcode) } return 0; } + +void close_process(pid_t pid) +{ + CloseHandle((HANDLE)pid); +} -- 2.11.4.GIT