[sane-devel] sane_init()/sane_exit() crashes on debian systems / not on e.g. arch linux

Wilhelm wilhelm.wm.meier at googlemail.com
Wed Apr 5 14:55:39 UTC 2017


Hi all,

the following small program regularly crashes on debian based system
when inserting / removing a device. This does not happen on e.g. arch
linux or gentoo systems.

Investigating the problem further reveals that on debian based systems
every iteration starts a new thread ending up with tons of threads:
thats obviously the problem here.

On ArchLinux the sane_exit() call termintates the thread started in
sane_init() abd therefore no crash happens here.

Any reasons or plans to fix that?

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <sane/sane.h>

int main () {
   while (true) {
       SANE_Int sane_version = 0;
       if (sane_init(&sane_version, 0) != SANE_STATUS_GOOD) {
           printf("Can't init sane\n");
           exit(EXIT_FAILURE);
       }
       printf("sane version %d.%d\n", SANE_VERSION_MAJOR(sane_version),
SANE_VERSION_MINOR(sane_version));

       const SANE_Device** device_list = NULL;
       if (sane_get_devices(&device_list, SANE_TRUE) == SANE_STATUS_GOOD) {
           const SANE_Device** dev = device_list;
           while (*dev) {
               printf("dev name: %s\n", (*dev)->name);
               dev++;
           }
       } else {
           printf("Can't get dev list\n");
           exit(EXIT_FAILURE);
       }
       sleep (1);
       printf("sane_exit\n");
       sane_exit();
       sleep (1);
   }
   exit(EXIT_SUCCESS);
}



More information about the sane-devel mailing list