From 6825e55b72831fd9a3ace1a49af7b00280404460 Mon Sep 17 00:00:00 2001 From: Benjamin Schug Date: Mon, 21 Oct 2024 14:30:57 +0200 Subject: [PATCH] Fix memory leak Any time a new client connects, it is added to the _clients array and never removed until the server stops. This fix removes disconnected clients from the list after processing each frame. --- addons/godottpd/http_server.gd | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/addons/godottpd/http_server.gd b/addons/godottpd/http_server.gd index 46c484c..4cb2d88 100644 --- a/addons/godottpd/http_server.gd +++ b/addons/godottpd/http_server.gd @@ -92,6 +92,11 @@ func _process(_delta: float) -> void: if bytes > 0: var request_string = client.get_utf8_string(bytes) self._handle_request(client, request_string) + _remove_disconnected_clients() + + +func _remove_disconnected_clients(): + self._clients = self._clients.filter(func(c: StreamPeerTCP): c.get_status() == StreamPeerTCP.STATUS_CONNECTED) # Start the server