From baf231808fbf6eec91fd8e094f15932b55281fb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9sz=C3=A1ros=20Gergely?= Date: Fri, 1 May 2026 00:41:57 +0200 Subject: [PATCH] fix: keep alive host data in uws_app_listen_with_config, related to bug #212 --- src/socketify/socketify.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/socketify/socketify.py b/src/socketify/socketify.py index cccd9bb..ff64cd0 100644 --- a/src/socketify/socketify.py +++ b/src/socketify/socketify.py @@ -3371,16 +3371,18 @@ async def task_wrapper(task): if isinstance(port, int) else ffi.cast("int", 0) ) - options.host = ( + host_cdata = ( ffi.new("char[]", host.encode("utf-8")) if isinstance(host, str) else ffi.NULL ) + options.host = host_cdata options.options = ( ffi.cast("int", options_) if isinstance(options_, int) else ffi.cast("int", 0) ) + self._native_options.append(host_cdata) # Keep alive (possible) char[] self.native_options_listen = native_options # Keep alive native_options lib.uws_app_listen_with_config( self.SSL, self.app, options, uws_generic_listen_handler, self._ptr @@ -3401,12 +3403,14 @@ async def task_wrapper(task): native_options = ffi.new("uws_app_listen_config_t *") options = native_options[0] options.port = ffi.cast("int", port_or_options.port) - options.host = ( + host_cdata = ( ffi.NULL if port_or_options.host is None else ffi.new("char[]", port_or_options.host.encode("utf-8")) ) + options.host = host_cdata options.options = ffi.cast("int", port_or_options.options) + self._native_options.append(host_cdata) # Keep alive (possible) char[] self.native_options_listen = native_options # Keep alive native_options lib.uws_app_listen_with_config( self.SSL, self.app, options, uws_generic_listen_handler, self._ptr