Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault in Genesys backend #15

Open
bsdice opened this issue Aug 24, 2020 · 0 comments
Open

Segmentation fault in Genesys backend #15

bsdice opened this issue Aug 24, 2020 · 0 comments

Comments

@bsdice
Copy link

bsdice commented Aug 24, 2020

Hi...

When no scanner is attached, there is a segfault happening here:

sane_exit();

Backtrace:

Thread 1 "insaned" received signal SIGSEGV, Segmentation fault.
0x00007ffff3d89d70 in std::_Function_handler<void (), genesys::StaticInit<std::vector<genesys::Genesys_USB_Device_Entry, std::allocator<genesys::Genesys_USB_Device_Entry> > >::init<>()::{lambda()#1}>::_M_invoke(std::_Any_data const&) () from /usr/lib/sane/libsane-genesys.so.1
(gdb) bt
#0  0x00007ffff3d89d70 in std::_Function_handler<void (), genesys::StaticInit<std::vector<genesys::Genesys_USB_Device_Entry, std::allocator<genesys::Genesys_USB_Device_Entry> > >::init<>()::{lambda()#1}>::_M_invoke(std::_Any_data const&) () from /usr/lib/sane/libsane-genesys.so.1
#1  0x00007ffff3d76645 in genesys::run_functions_at_backend_exit() () from /usr/lib/sane/libsane-genesys.so.1
#2  0x00007ffff3d03bb6 in genesys::sane_exit_impl() () from /usr/lib/sane/libsane-genesys.so.1
#3  0x00007ffff3d03bf7 in sane_genesys_exit () from /usr/lib/sane/libsane-genesys.so.1
#4  0x00007ffff7f9641e in sane_dll_exit () from /usr/lib/libsane.so.1
#5  0x000055555555a7a4 in InsaneDaemon::~InsaneDaemon (this=0x55555556a760 <InsaneDaemon::mInstance>, __in_chrg=<optimized out>) at src/InsaneDaemon.cpp:61
#6  0x00007ffff7ac8db7 in __run_exit_handlers () from /usr/lib/libc.so.6
#7  0x00007ffff7ac8f5e in exit () from /usr/lib/libc.so.6
#8  0x00007ffff7ab1159 in __libc_start_main () from /usr/lib/libc.so.6
#9  0x000055555555762e in _start ()

So I modified the function like this, no idea if this is correct though:

diff --git a/src/InsaneDaemon.cpp b/src/InsaneDaemon.cpp
index db8ff1c..41bbd71 100644
--- a/src/InsaneDaemon.cpp
+++ b/src/InsaneDaemon.cpp
@@ -53,18 +53,18 @@ InsaneDaemon::InsaneDaemon()
 
 InsaneDaemon::~InsaneDaemon() noexcept
 {
+    SANE_Handle mHandle2 = mHandle;
     log("Exiting...", 1);
     close();
     try {
-        mHandle = nullptr;
-        log("Calling sane_exit", 1);
-        sane_exit();
-
+        if (mHandle2) {
+            log("Calling sane_exit", 1);
+            sane_exit();
+        }
+        log("Finished", 1);
         ::close(0);
         ::close(1);
         ::close(2);
-
-        log("Finished", 1);
     } catch (...) {
         log("Error calling sane_exit!", 0);
     }
  • Introduced mHandle2 to save mHandle before close(); nulls it
  • Don't null mHandle twice (in close() and here)
  • Only call sane_exit() if mHandle2 contains a handle
  • Print log(Finished) before closing all stdandard descriptors
xeijin pushed a commit to xeijin/insaned that referenced this issue Jan 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant