From 62d05674ba1bdb7437fae8f0cd91b54f00ed5fe0 Mon Sep 17 00:00:00 2001 From: jolavillette Date: Sat, 15 Aug 2026 09:34:16 +0200 Subject: [PATCH] jsonapi: do not replace rsJsonApi silently, and assign it once startupWebServices() casts rsJsonApi to JsonApiServer to reuse the instance the plugin handoff created. If that cast ever fails, the previous code built a second server and overwrote the global without a word -- while every plugin still holds the pointer it was handed in setInterfaces(), now pointing at an object nobody drives. Unreachable as things stand, since rsJsonApi is only ever set to a JsonApiServer; worth one line of log rather than a silent swap. The trailing `rsJsonApi = jas;` at the end of the function repeated what the same function already did on the line above the cast, and only when it had created the server itself. Dropped. --- src/rsserver/rsinit.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/rsserver/rsinit.cc b/src/rsserver/rsinit.cc index 11c1e7534..dd0cdddb3 100644 --- a/src/rsserver/rsinit.cc +++ b/src/rsserver/rsinit.cc @@ -451,6 +451,15 @@ void RsInit::startupWebServices(const RsConfigOptions& conf,bool force_start_jso JsonApiServer* jas = dynamic_cast(rsJsonApi); if(!jas) { + /* Not reachable today -- rsJsonApi is only ever set to a JsonApiServer, + * here and in the plugin handoff of StartupRetroShare(). Should that + * change, replacing it silently would leave every plugin holding the + * pointer it received in setInterfaces() talking to an abandoned + * object, with no trace of why. */ + if(rsJsonApi) + RsErr() << "rsJsonApi is set but is not a JsonApiServer. Replacing " + << "it: plugins still hold the previous pointer."; + jas = new JsonApiServer(); rsJsonApi = jas; } @@ -537,8 +546,6 @@ void RsInit::startupWebServices(const RsConfigOptions& conf,bool force_start_jso } else RsInfo() << " Not starting JSON API, since it is currently not required by any service." ; - - rsJsonApi = jas; } #endif