diff --git a/zulip/integrations/zephyr/check-mirroring b/zulip/integrations/zephyr/check-mirroring index 67ccb249..bd49c805 100755 --- a/zulip/integrations/zephyr/check-mirroring +++ b/zulip/integrations/zephyr/check-mirroring @@ -228,6 +228,7 @@ def receive_zephyrs() -> None: logging.exception("Exception receiving zephyrs:") break if notice.z_opcode != b"": + zephyr_ctypes.ZFreeNotice(byref(notice)) continue notices.append(notice) @@ -335,6 +336,9 @@ z_contents = [ (h_key_counts, h_missing_z, h_missing_h, h_duplicates, h_success) = process_keys(h_contents) (z_key_counts, z_missing_z, z_missing_h, z_duplicates, z_success) = process_keys(z_contents) +for notice in notices: + zephyr_ctypes.ZFreeNotice(byref(notice)) + if z_success and h_success: logger.info("Success!") print_status_and_exit(0) diff --git a/zulip/integrations/zephyr/zephyr_ctypes.py b/zulip/integrations/zephyr/zephyr_ctypes.py index ef35f0a3..5817498b 100644 --- a/zulip/integrations/zephyr/zephyr_ctypes.py +++ b/zulip/integrations/zephyr/zephyr_ctypes.py @@ -167,6 +167,7 @@ ZGetSubscriptions = CFUNCTYPE(Code_t, POINTER(ZSubscription_t), POINTER(c_int))( ) ZOpenPort = CFUNCTYPE(Code_t, POINTER(c_ushort))(("ZOpenPort", libzephyr)) ZFlushSubscriptions = CFUNCTYPE(Code_t)(("ZFlushSubscriptions", libzephyr)) +ZFreeNotice = CFUNCTYPE(Code_t, POINTER(ZNotice_t))(("ZFreeNotice", libzephyr)) ZSubscribeTo = CFUNCTYPE(Code_t, POINTER(ZSubscription_t), c_int, c_uint)( ("ZSubscribeTo", libzephyr) ) diff --git a/zulip/integrations/zephyr/zephyr_mirror_backend.py b/zulip/integrations/zephyr/zephyr_mirror_backend.py index 2e906090..28adf7c2 100755 --- a/zulip/integrations/zephyr/zephyr_mirror_backend.py +++ b/zulip/integrations/zephyr/zephyr_mirror_backend.py @@ -321,13 +321,15 @@ def process_loop(zulip_queue: "Queue[ZephyrDict]", log: Optional[IO[str]]) -> No notice = zephyr_ctypes.ZNotice_t() sender = zephyr_ctypes.sockaddr_in() zephyr_ctypes.check(zephyr_ctypes.ZReceiveNotice(byref(notice), byref(sender))) - recieve_backoff.succeed() try: + recieve_backoff.succeed() process_notice(notice, zulip_queue, log) process_backoff.succeed() except zephyr_ctypes.ZephyrError: logger.exception("Error relaying zephyr:") process_backoff.fail() + finally: + zephyr_ctypes.ZFreeNotice(byref(notice)) except zephyr_ctypes.ZephyrError: logger.exception("Error checking for new zephyrs:") recieve_backoff.fail()