File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -52,6 +52,8 @@ typedef struct {
5252
5353static PyTypeObject SaneDev_Type ;
5454
55+ static int g_sane_initialized = 0 ;
56+
5557
5658/* Raise a SANE exception */
5759static PyObject *
@@ -66,7 +68,7 @@ PySane_Error(SANE_Status st)
6668static void
6769SaneDev_dealloc (SaneDevObject * self )
6870{
69- if (self -> h )
71+ if (self -> h && g_sane_initialized )
7072 sane_close (self -> h );
7173 self -> h = NULL ;
7274 PyObject_DEL (self );
@@ -658,7 +660,7 @@ PySane_init(PyObject *self, PyObject *args)
658660 SANE_Status st = sane_init (& version , NULL );
659661 if (st != SANE_STATUS_GOOD )
660662 return PySane_Error (st );
661-
663+ g_sane_initialized = 1 ;
662664 return Py_BuildValue ("iiii" , version ,
663665 SANE_VERSION_MAJOR (version ),
664666 SANE_VERSION_MINOR (version ),
@@ -672,6 +674,7 @@ PySane_exit(PyObject *self, PyObject *args)
672674 return NULL ;
673675
674676 sane_exit ();
677+ g_sane_initialized = 0 ;
675678 Py_INCREF (Py_None );
676679 return Py_None ;
677680}
You can’t perform that action at this time.
0 commit comments