diff options
| author | Justin M. Keyes <justinkz@gmail.com> | 2021-09-01 07:29:38 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-01 07:29:38 -0700 |
| commit | 0603eba6e713b2bd25cbbb55caf2342b0ccdece9 (patch) | |
| tree | 79c1d699fd6a301e6fb8afb6d4510c93e2184627 /src/nvim/event | |
| parent | 5c643dee7bca26c933f7abfcf2757ccd8cb07af6 (diff) | |
| download | rneovim-0603eba6e713b2bd25cbbb55caf2342b0ccdece9.tar.gz rneovim-0603eba6e713b2bd25cbbb55caf2342b0ccdece9.tar.bz2 rneovim-0603eba6e713b2bd25cbbb55caf2342b0ccdece9.zip | |
feat(api): nvim_get_chan_info: include "argv" for jobs #15537
ref #15440
Diffstat (limited to 'src/nvim/event')
| -rw-r--r-- | src/nvim/event/process.c | 20 | ||||
| -rw-r--r-- | src/nvim/event/process.h | 1 |
2 files changed, 17 insertions, 4 deletions
diff --git a/src/nvim/event/process.c b/src/nvim/event/process.c index a2aafc94c8..8b366d0f3c 100644 --- a/src/nvim/event/process.c +++ b/src/nvim/event/process.c @@ -88,7 +88,7 @@ int process_spawn(Process *proc, bool in, bool out, bool err) } else { process_close(proc); } - shell_free_argv(proc->argv); + process_free(proc); proc->status = -1; return status; } @@ -201,7 +201,7 @@ int process_wait(Process *proc, int ms, MultiQueue *events) // Job exited, free its resources. decref(proc); if (proc->events) { - // the decref call created an exit event, process it now + // decref() created an exit event, process it now. multiqueue_process_events(proc->events); } } else { @@ -239,6 +239,15 @@ void process_stop(Process *proc) FUNC_ATTR_NONNULL_ALL KILL_TIMEOUT_MS, 0); } +// Frees process-owned resources. +void process_free(Process *proc) FUNC_ATTR_NONNULL_ALL +{ + if (proc->argv != NULL) { + shell_free_argv(proc->argv); + proc->argv = NULL; + } +} + /// Sends SIGKILL (or SIGTERM..SIGKILL for PTY jobs) to processes that did /// not terminate after process_stop(). static void children_kill_cb(uv_timer_t *handle) @@ -269,9 +278,12 @@ static void children_kill_cb(uv_timer_t *handle) static void process_close_event(void **argv) { Process *proc = argv[0]; - shell_free_argv(proc->argv); - if (proc->cb) { // "on_exit" for jobstart(). See channel_job_start(). + if (proc->cb) { + // User (hint: channel_job_start) is responsible for calling + // process_free(). proc->cb(proc, proc->status, proc->data); + } else { + process_free(proc); } } diff --git a/src/nvim/event/process.h b/src/nvim/event/process.h index 24debdb276..20c02e4900 100644 --- a/src/nvim/event/process.h +++ b/src/nvim/event/process.h @@ -26,6 +26,7 @@ struct process { char **argv; dict_T *env; Stream in, out, err; + /// Exit handler. If set, user must call process_free(). process_exit_cb cb; internal_process_cb internal_exit_cb, internal_close_cb; bool closed, detach, overlapped; |