Skip to content

Commit

Permalink
protocol: free memory allocated for url args
Browse files Browse the repository at this point in the history
  • Loading branch information
tsl0922 committed Mar 14, 2021
1 parent b819e9e commit c0bdd7b
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ static bool check_host_origin(struct lws *wsi) {

static void process_read_cb(void *ctx, pty_buf_t *buf, bool eof) {
struct pss_tty *pss = (struct pss_tty *) ctx;
pss->pty_buf = buf;
if (eof && !process_running(pss->process)) {
if (eof && !process_running(pss->process))
pss->lws_close_status = pss->process->exit_code == 0 ? 1000 : 1006;
}
else
pss->pty_buf = buf;

lws_callback_on_writable(pss->wsi);
}

Expand Down Expand Up @@ -130,7 +131,6 @@ static void wsi_output(struct lws *wsi, pty_buf_t *buf) {
memcpy(wbuf + LWS_PRE + 1, buf->base, buf->len);
wbuf[LWS_PRE] = OUTPUT;
size_t n = buf->len + 1;
pty_buf_free(buf);
if (lws_write(wsi, (unsigned char *) wbuf + LWS_PRE, n, LWS_WRITE_BINARY) < n) {
lwsl_err("write OUTPUT to WS\n");
}
Expand Down Expand Up @@ -173,11 +173,8 @@ int callback_tty(struct lws *wsi, enum lws_callback_reasons reason, void *user,

case LWS_CALLBACK_ESTABLISHED:
pss->initialized = false;
pss->initial_cmd_index = 0;
pss->authenticated = false;
pss->wsi = wsi;
pss->buffer = NULL;
pss->pty_buf = NULL;
pss->lws_close_status = LWS_CLOSE_STATUS_NOSTATUS;

if (server->url_arg) {
Expand Down Expand Up @@ -226,6 +223,7 @@ int callback_tty(struct lws *wsi, enum lws_callback_reasons reason, void *user,

if (pss->pty_buf != NULL) {
wsi_output(wsi, pss->pty_buf);
pty_buf_free(pss->pty_buf);
pss->pty_buf = NULL;
pty_resume(pss->process);
}
Expand Down Expand Up @@ -317,6 +315,9 @@ int callback_tty(struct lws *wsi, enum lws_callback_reasons reason, void *user,
if (pss->buffer != NULL) {
free(pss->buffer);
}
for (int i = 0; i < pss->argc; i++) {
free(pss->args[i]);
}

if (process_running(pss->process)) {
pty_pause(pss->process);
Expand Down

0 comments on commit c0bdd7b

Please sign in to comment.