From 59c48cdd62a99f6047c134057949350a2559d7c1 Mon Sep 17 00:00:00 2001 From: Ashish Bansal Date: Sun, 8 Dec 2019 00:06:38 +0530 Subject: [PATCH] Fix memory leaks in LspEndpoint --- pylspclient/lsp_endpoint.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pylspclient/lsp_endpoint.py b/pylspclient/lsp_endpoint.py index 48f2df4..2e756a5 100644 --- a/pylspclient/lsp_endpoint.py +++ b/pylspclient/lsp_endpoint.py @@ -59,7 +59,7 @@ class LspEndpoint(threading.Thread): else: self.handle_result(rpc_id, result, error) except lsp_structs.ResponseError as e: - self.send_response(rpc_id, None, e) + self.send_response(rpc_id, None, e) def send_response(self, id, result, error): @@ -71,7 +71,7 @@ class LspEndpoint(threading.Thread): if error: message_dict["error"] = error self.json_rpc_endpoint.send_request(message_dict) - + def send_message(self, method_name, params, id = None): message_dict = {} @@ -81,18 +81,21 @@ class LspEndpoint(threading.Thread): message_dict["method"] = method_name message_dict["params"] = params self.json_rpc_endpoint.send_request(message_dict) - + def call_method(self, method_name, **kwargs): current_id = self.next_id self.next_id += 1 cond = threading.Condition() self.event_dict[current_id] = cond + cond.acquire() self.send_message(method_name, kwargs, current_id) cond.wait() cond.release() - result, error = self.response_dict[current_id] + + self.event_dict.pop(current_id) + result, error = self.response_dict.pop(current_id) if error: raise lsp_structs.ResponseError(error.get("code"), error.get("message"), error.get("data")) return result