From 688c948f51236a6414bab03c01af14f9e23e896e Mon Sep 17 00:00:00 2001 From: ultrafunkamsterdam Date: Sat, 6 Jul 2024 16:25:09 +0200 Subject: [PATCH] 0.31 fix memory leak - thanks zxsleebu --- nodriver/core/_contradict.py | 2 +- nodriver/core/connection.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/nodriver/core/_contradict.py b/nodriver/core/_contradict.py index e35434d..c770361 100644 --- a/nodriver/core/_contradict.py +++ b/nodriver/core/_contradict.py @@ -139,7 +139,7 @@ def _camel_to_snake(s): :param str s: string to be converted :return: (str) snake_case version of s """ - s = s.replace("-", "").replace(".", "") + s = s.replace("-", "").replace(".", "").replace(" ", "_") return __RE_CAMEL_TO_SNAKE__.sub(r"_\1", s).lower() diff --git a/nodriver/core/connection.py b/nodriver/core/connection.py index dfc3fff..51606d0 100644 --- a/nodriver/core/connection.py +++ b/nodriver/core/connection.py @@ -551,8 +551,12 @@ async def listener_loop(self): # response to our command if message["id"] in self.connection.mapper: # get the corresponding Transaction - tx = self.connection.mapper[message["id"]] + + # pop to prevent memory leaks + # thanks to zxsleebu + tx = self.connection.mapper.pop(message["id"]) logger.debug("got answer for %s", tx) + # complete the transaction, which is a Future object # and thus will return to anyone awaiting it. tx(**message)