Skip to content

Commit e192426

Browse files
committed
rtc: don't put ffi_drop_handle side effect inside assert
With python -O asserts are stripped, which would skip the drop and leak the native handle. Call drop_handle unconditionally and assert the result separately.
1 parent 5472a7c commit e192426

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

livekit-rtc/livekit/rtc/_ffi_client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ def dispose(self) -> None:
8585
self._disposed = True
8686
ffi = FfiClient._owned_instance()
8787
if ffi is not None:
88-
assert ffi._ffi_lib.livekit_ffi_drop_handle(ctypes.c_uint64(self.handle))
88+
# Keep the drop out of assert(): with `python -O` asserts are
89+
# stripped, which would skip the call and leak the handle.
90+
dropped = ffi._ffi_lib.livekit_ffi_drop_handle(ctypes.c_uint64(self.handle))
91+
assert dropped
8992

9093
def __repr__(self) -> str:
9194
return f"FfiHandle({self.handle})"

0 commit comments

Comments
 (0)