File fix-scanner-search-crash.patch of Package ksanecore

From ee34096fefa78887d102fa65f2492aa4cb215f37 Mon Sep 17 00:00:00 2001
From: Andras Mantia <andras.mantia@kdab.com>
Date: Tue, 28 May 2024 12:30:59 +0300
Subject: [PATCH] Don't crash scanner apps (skanlite, skanpage) when searching
 for scanners

This is triggered eg. with network scanners where scanning takes longer time.
As comment says: this defeats the idea of using a scanner thread,
but the proper fix would be more elaborate (ie. do the rest of initialization
only when the thread is finished).
Still makes sense to have this hotfix, especially as this is an old bug...

BUG: 444987
BUG: 468053
---
 src/interface_p.cpp | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/interface_p.cpp b/src/interface_p.cpp
index e7cb9a3..1af5de3 100644
--- a/src/interface_p.cpp
+++ b/src/interface_p.cpp
@@ -95,6 +95,13 @@ Interface::OpenStatus InterfacePrivate::loadDeviceOptions()
         }
     }
 
+    // need to wait as calling sane_get_devices and sane_control_option (that happens later)
+    // from two different threads at the same time causes a crash, libsane looks to be not
+    // thread safe.
+    // It defeats the purpose of the thread and make startup slower, but it is better than crashing.
+    if (m_findDevThread->isRunning())
+        m_findDevThread->wait();
+
     // Read the options (start with option 0 the number of parameters)
     optDesc = sane_get_option_descriptor(m_saneHandle, 0);
     if (optDesc == nullptr) {
-- 
GitLab

openSUSE Build Service is sponsored by