]> prime8.dev >> repos - ttyd.git/commitdiff
protocol: cleanup unused code
authorShuanglei Tao <tsl0922@gmail.com>
Thu, 11 Mar 2021 14:56:07 +0000 (22:56 +0800)
committerShuanglei Tao <tsl0922@gmail.com>
Thu, 11 Mar 2021 14:56:49 +0000 (22:56 +0800)
src/protocol.c
src/pty.c

index 8523b72dde9f177e186c7a07528dc4cc038b77e7..e689acf8d1f0468dc3f19045c9e2e5d6e2eeab27 100644 (file)
@@ -258,14 +258,7 @@ int callback_tty(struct lws *wsi, enum lws_callback_reasons reason, void *user,
       switch (command) {
         case INPUT:
           if (server->readonly) break;
-
-          char *data = xmalloc(pss->len - 1);
-          memcpy(data, pss->buffer + 1, pss->len - 1);
-
-          uv_write_t *req = xmalloc(sizeof(uv_write_t));
-          req->data = data;
-
-          int err = pty_write(pss->process, pty_buf_init(data, pss->len - 1));
+          int err = pty_write(pss->process, pty_buf_init(pss->buffer + 1, pss->len - 1));
           if (err) {
             lwsl_err("uv_write: %s (%s)\n", uv_err_name(err), uv_strerror(err));
             return -1;
index 1db5baa2d43bb6730801101db54f33fa91eab064..03f6557af70ae0b9adccc6989832b4f38c82478a 100644 (file)
--- a/src/pty.c
+++ b/src/pty.c
@@ -136,7 +136,10 @@ void pty_resume(pty_process *process) {
 }
 
 int pty_write(pty_process *process, pty_buf_t *buf) {
-  if (process == NULL) return UV_ESRCH;
+  if (process == NULL) {
+    pty_buf_free(buf);
+    return UV_ESRCH;
+  }
   pty_io_t *io = process->io;
   uv_buf_t b = uv_buf_init(buf->base, buf->len);
   uv_write_t *req = xmalloc(sizeof(uv_write_t));