close(pss->pty);
// free the buffer
- if (pss->buffer != NULL)
+ if (pss->buffer != NULL) {
free(pss->buffer);
- if (pss->pty_buffer != NULL)
+ pss->buffer = NULL;
+ }
+ if (pss->pty_buffer != NULL) {
free(pss->pty_buffer);
+ pss->pty_buffer = NULL;
+ }
for (int i = 0; i < pss->argc; i++) {
free(pss->args[i]);
struct pss_tty *pss = (struct pss_tty *) stream->data;
pss->pty_len = nread;
+ uv_read_stop(stream);
+
if (nread <= 0) {
if (nread == UV_ENOBUFS || nread == 0)
return;
+ pss->pty_buffer = NULL;
if (nread == UV_EOF)
pss->pty_len = 0;
else
lwsl_err("read_cb: %s\n", uv_err_name(nread));
- pss->pty_buffer = NULL;
} else {
pss->pty_buffer = xmalloc(LWS_PRE + 1 + (size_t ) nread);
memcpy(pss->pty_buffer + LWS_PRE + 1, buf->base, (size_t ) nread);
free(buf->base);
lws_callback_on_writable(pss->wsi);
- uv_read_stop(stream);
}
void
if (pid > 0) {
lwsl_notice("process exited with code %d, pid: %d\n", status, pid);
pss->pid = 0;
+ pss->pty_len = status > 0 ? -status : status;
pss_tty_free(pss);
}
}
case LWS_CALLBACK_CLOSED:
server->client_count--;
lwsl_notice("WS closed from %s, clients: %d\n", pss->address, server->client_count);
+ uv_read_stop((uv_stream_t *) &pss->pipe);
kill_process(pss->pid, server->sig_code);
if (server->once && server->client_count == 0) {
lwsl_notice("exiting due to the --once option.\n");