From e1fb71a40191aff60ea8f44e27b00fc2c7ae7267 Mon Sep 17 00:00:00 2001 From: Jan Streffing Date: Sun, 3 May 2026 09:12:57 +0200 Subject: [PATCH] xios: null-guard CXios::globalRegistry deref in CContext::finalize In attached mode (using_server=false) CContext::finalize hits the 'Mode attache' branch which dereferences CXios::globalRegistry unconditionally. CXios::globalRegistry is only allocated on client rank 0 (cxios.cpp:112) but the merge is gated on server->intraCommRank==0; in attached mode those two ranks need not coincide, so a non-rank-0 process segfaults in xios::CRegistry::mergeRegistry at xios_context_finalize. Add a null check; the patched line is equivalent for server mode (globalRegistry is always non-null on the server's rank 0) but lets attached-mode FESOM_WITH_XIOS=ON runs exit cleanly. Verified locally on Levante (intel + openmpi, 2-rank pi mesh, 6 XIOS-output fields): without patch SIGSEGV in xios_close, with patch 'fesom should stop with exit status = 0'. --- fesom2_ci/xios/src/node/context.cpp | 4 ++-- fesom2_test_refactoring/xios/src/node/context.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fesom2_ci/xios/src/node/context.cpp b/fesom2_ci/xios/src/node/context.cpp index a33e23ca..39515bc9 100644 --- a/fesom2_ci/xios/src/node/context.cpp +++ b/fesom2_ci/xios/src/node/context.cpp @@ -494,7 +494,7 @@ namespace xios { { closeAllFile(); registryOut->hierarchicalGatherRegistry() ; - if (server->intraCommRank==0) CXios::globalRegistry->mergeRegistry(*registryOut) ; + if (server->intraCommRank==0 && CXios::globalRegistry) CXios::globalRegistry->mergeRegistry(*registryOut) ; } //! Deallocate client buffers @@ -534,7 +534,7 @@ namespace xios { if (hasServer && !hasClient) { registryOut->hierarchicalGatherRegistry() ; - if (server->intraCommRank==0) CXios::globalRegistry->mergeRegistry(*registryOut) ; + if (server->intraCommRank==0 && CXios::globalRegistry) CXios::globalRegistry->mergeRegistry(*registryOut) ; } //! Deallocate client buffers diff --git a/fesom2_test_refactoring/xios/src/node/context.cpp b/fesom2_test_refactoring/xios/src/node/context.cpp index a33e23ca..39515bc9 100644 --- a/fesom2_test_refactoring/xios/src/node/context.cpp +++ b/fesom2_test_refactoring/xios/src/node/context.cpp @@ -494,7 +494,7 @@ namespace xios { { closeAllFile(); registryOut->hierarchicalGatherRegistry() ; - if (server->intraCommRank==0) CXios::globalRegistry->mergeRegistry(*registryOut) ; + if (server->intraCommRank==0 && CXios::globalRegistry) CXios::globalRegistry->mergeRegistry(*registryOut) ; } //! Deallocate client buffers @@ -534,7 +534,7 @@ namespace xios { if (hasServer && !hasClient) { registryOut->hierarchicalGatherRegistry() ; - if (server->intraCommRank==0) CXios::globalRegistry->mergeRegistry(*registryOut) ; + if (server->intraCommRank==0 && CXios::globalRegistry) CXios::globalRegistry->mergeRegistry(*registryOut) ; } //! Deallocate client buffers