From 4e134b578cc169ae4a254396da95d66fc0a3d182 Mon Sep 17 00:00:00 2001 From: Lauri Kasanen Date: Fri, 24 Jun 2022 17:27:33 +0000 Subject: [PATCH] Resolve KASM-2798 "Bugfix/ memory leak" --- .gitmodules | 2 +- common/network/TcpSocket.cxx | 2 ++ common/network/websocket.c | 15 ++++++++++++--- kasmweb | 2 +- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.gitmodules b/.gitmodules index 8f7f4a8..e43a13a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "kasmweb"] path = kasmweb url = https://github.com/kasmtech/noVNC.git - branch = feature/KASM-2634_UI_updates + branch = master diff --git a/common/network/TcpSocket.cxx b/common/network/TcpSocket.cxx index 6353358..cb82c3c 100644 --- a/common/network/TcpSocket.cxx +++ b/common/network/TcpSocket.cxx @@ -931,6 +931,8 @@ void network::createWebsocketListeners(std::list *listeners, freeaddrinfo(ai); throw; } + + freeaddrinfo(ai); } } diff --git a/common/network/websocket.c b/common/network/websocket.c index 960ba22..4005d95 100644 --- a/common/network/websocket.c +++ b/common/network/websocket.c @@ -249,6 +249,7 @@ void free_ws_ctx(ws_ctx_t *ctx) { free(ctx->cout_buf); free(ctx->tin_buf); free(ctx->tout_buf); + free(ctx->headers); free(ctx); } @@ -947,7 +948,8 @@ static void servefile(ws_ctx_t *ws_ctx, const char *in, const char * const user, "Content-length: %lu\r\n" "\r\n", name2mime(path), filesize); - ws_send(ws_ctx, buf, strlen(buf)); + const unsigned hdrlen = strlen(buf); + ws_send(ws_ctx, buf, hdrlen); //fprintf(stderr, "http servefile output '%s'\n", buf); @@ -957,7 +959,7 @@ static void servefile(ws_ctx_t *ws_ctx, const char *in, const char * const user, } fclose(f); - weblog(200, wsthread_handler_id, 0, origip, ip, user, 1, path, strlen(buf) + filesize); + weblog(200, wsthread_handler_id, 0, origip, ip, user, 1, path, hdrlen + filesize); return; nope: @@ -1947,7 +1949,14 @@ void *start_server(void *unused) { pthread_t tid; pass->id = settings.handler_id; pass->csock = csock; - pthread_create(&tid, NULL, subthread, pass); + + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + + pthread_create(&tid, &attr, subthread, pass); + + pthread_attr_destroy(&attr); settings.handler_id += 1; } diff --git a/kasmweb b/kasmweb index 9a6f971..7e5a302 160000 --- a/kasmweb +++ b/kasmweb @@ -1 +1 @@ -Subproject commit 9a6f97115cf8fbbe7242cf6c4117da54cc6d7a24 +Subproject commit 7e5a302a7a47472a679391ef24b18a78c936a9f6