]> prime8.dev >> repos - ttyd.git/commitdiff
protocol: fix a regression that may crashes the server
authorShuanglei Tao <tsl0922@gmail.com>
Tue, 9 Jan 2018 16:09:30 +0000 (00:09 +0800)
committerShuanglei Tao <tsl0922@gmail.com>
Tue, 9 Jan 2018 16:09:39 +0000 (00:09 +0800)
src/protocol.c

index 70fdc6c67757ac7803f0629b670a68669f2eed2c..845718c4725635cec94312817e34cbfdb44c2759 100644 (file)
@@ -99,7 +99,8 @@ tty_client_remove(struct tty_client *client) {
 void
 tty_client_destroy(struct tty_client *client) {
     if (!client->running || client->pid <= 0)
-        return;
+        goto cleanup;
+
     client->running = false;
 
     // kill process and free resource
@@ -113,6 +114,7 @@ tty_client_destroy(struct tty_client *client) {
     lwsl_notice("process exited with code %d, pid: %d\n", status, client->pid);
     close(client->pty);
 
+cleanup:
     // free the buffer
     if (client->buffer != NULL)
         free(client->buffer);