1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-24 15:28:10 +00:00

python: ensure client session counter is never negative

This commit is contained in:
matejcik 2019-10-18 13:31:13 +02:00
parent 3f9b0b7f4f
commit 598e828844
2 changed files with 4 additions and 4 deletions

View File

@ -132,9 +132,9 @@ class TrezorClient:
self.session_counter += 1
def close(self):
if self.session_counter == 1:
self.session_counter = max(self.session_counter - 1, 0)
if self.session_counter == 0:
self.transport.end_session()
self.session_counter -= 1
def cancel(self):
self._raw_write(messages.Cancel())

View File

@ -93,9 +93,9 @@ class Protocol:
self.session_counter += 1
def end_session(self) -> None:
if self.session_counter == 1:
self.session_counter = max(self.session_counter - 1, 0)
if self.session_counter == 0:
self.handle.close()
self.session_counter -= 1
def read(self) -> protobuf.MessageType:
raise NotImplementedError