protocol: fix potential pty buf leak

This commit is contained in:
Shuanglei Tao
2022-08-18 10:35:23 +08:00
parent eb055722cb
commit 6cfd9b29ae
4 changed files with 43 additions and 21 deletions

View File

@@ -51,7 +51,8 @@ pty_buf_t *pty_buf_init(char *base, size_t len) {
}
void pty_buf_free(pty_buf_t *buf) {
free(buf->base);
if (buf == NULL) return;
if (buf->base != NULL) free(buf->base);
free(buf);
}
@@ -105,6 +106,7 @@ void process_free(pty_process *process) {
#else
uv_thread_join(&process->tid);
#endif
close(process->pty);
if (process->in != NULL) uv_close((uv_handle_t *) process->in, close_cb);
if (process->out != NULL) uv_close((uv_handle_t *) process->out, close_cb);
if (process->argv != NULL) free(process->argv);
@@ -153,7 +155,6 @@ bool pty_resize(pty_process *process) {
bool pty_kill(pty_process *process, int sig) {
if (process == NULL) return false;
process->killed = true;
#ifdef _WIN32
return TerminateProcess(process->handle, 1) != 0;
#else