From: Tito Brasolin Date: Fri, 5 Sep 2025 08:09:16 +0000 (+0200) Subject: ubus: unregister ubus subscriber on HTTP client disconnect X-Git-Url: http://git.cdn.openwrt.org/?a=commitdiff_plain;h=506e24987b97fbc866005bfb71316bd63601a1ef;p=project%2Fuhttpd.git ubus: unregister ubus subscriber on HTTP client disconnect Fixes a potential SIGSEGV when a client disconnects from a /ubus/subscribe/... endpoint without unsubscribing. The ubus subscriber is now properly unregistered in a cleanup handler, preventing callbacks on freed client structures. Fixes: #1 Signed-off-by: Tito Brasolin Link: https://github.com/openwrt/uhttpd/pull/18 Signed-off-by: Robert Marko --- diff --git a/ubus.c b/ubus.c index 99cc400..4b15466 100644 --- a/ubus.c +++ b/ubus.c @@ -362,6 +362,14 @@ static void uh_ubus_subscription_notification_remove_cb(struct ubus_context *ctx ops->request_done(cl); } +/* Cleanup function to unregister ubus subscriber when HTTP client closes */ +static void uh_ubus_subscription_free(struct client *cl) +{ + struct dispatch_ubus *du = &cl->dispatch.ubus; + if (du->sub.obj.id) + ubus_unregister_subscriber(ctx, &du->sub); +} + static void uh_ubus_handle_get_subscribe(struct client *cl, const char *path) { struct dispatch_ubus *du = &cl->dispatch.ubus; @@ -399,6 +407,9 @@ static void uh_ubus_handle_get_subscribe(struct client *cl, const char *path) if (conf.events_retry) ops->chunk_printf(cl, "retry: %d\n", conf.events_retry); + /* Ensure cleanup on client disconnect */ + cl->dispatch.free = uh_ubus_subscription_free; + return; err_unregister: