From 5238ac8e61147fae69a8515b473cb78fb27535c8 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Mon, 4 Dec 2023 15:18:27 +0100 Subject: [PATCH] OSRPJContextHolder: call pthread_atfork() once for the process Cf https://lists.osgeo.org/pipermail/gdal-dev/2023-December/058058.html --- ogr/ogr_proj_p.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ogr/ogr_proj_p.cpp b/ogr/ogr_proj_p.cpp index a27a84fe1975..f160cc9c96ea 100644 --- a/ogr/ogr_proj_p.cpp +++ b/ogr/ogr_proj_p.cpp @@ -121,7 +121,17 @@ struct OSRPJContextHolder #endif { #if HAVE_PTHREAD_ATFORK - pthread_atfork(nullptr, nullptr, ForkOccurred); + static std::once_flag flag; + std::call_once( + flag, + []() + { + if (pthread_atfork(nullptr, nullptr, ForkOccurred) != 0) + { + CPLError(CE_Failure, CPLE_OutOfMemory, + "pthread_atfork() in ogr_proj_p failed"); + } + }); #endif init(); }