From 5e3fe53bdbbb5a794fba1c9dd3a2c79fb1476028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Tue, 25 Aug 2026 08:45:58 +0000 Subject: [PATCH] cid#562881 Double unlock MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit the double-unlock finding is a bit bogus, but there is a real oddity here worth fixing. since: commit 6c9909dee4b06948ca6932397caa338d77ec7290 Date: Fri Oct 22 14:11:39 2021 +0200 fix std::unique_lock unlocking 84a54f6c388d3abe1d6f6e04bf07441ae96f60cd moved the end() test inside the guard, but left the dereference outside it Signed-off-by: Caolán McNamara Change-Id: Ia439ebffc9179e74d926efc7c3ea7dec2fc1f7db Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/9964 Reviewed-by: Noel Grandin Tested-by: Jenkins CPCI (cherry picked from commit 791c9f631b0ce352d356f5486ba537c9a4d3f8fc) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/210134 Tested-by: Jenkins Reviewed-by: Xisco Fauli --- sal/osl/unx/backtraceapi.cxx | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/sal/osl/unx/backtraceapi.cxx b/sal/osl/unx/backtraceapi.cxx index 1a39af42afe8..64a5800d57e5 100644 --- a/sal/osl/unx/backtraceapi.cxx +++ b/sal/osl/unx/backtraceapi.cxx @@ -203,16 +203,20 @@ OUString sal::backtrace_to_string(BacktraceState* backtraceState) { Dl_info dli; void* addr = backtraceState->buffer[i]; - std::unique_lock guard(frameCacheMutex); - auto it = frameCache.find(addr); - bool found = it != frameCache.end(); - guard.unlock(); - if( found ) + bool found = false; { - frameData[ i ].info = it->second; - frameData[ i ].handled = true; + // The cache evicts its oldest entry when a new one arrives, so copy the string out + // while the lock is held. + std::lock_guard guard(frameCacheMutex); + auto it = frameCache.find(addr); + if (it != frameCache.end()) + { + frameData[ i ].info = it->second; + frameData[ i ].handled = true; + found = true; + } } - else if (dladdr(addr, &dli) != 0) + if (!found && dladdr(addr, &dli) != 0) { if (dli.dli_fname && dli.dli_fbase) {