Skip to content

Commit 659131a

Browse files
committed
Don't call sane_close on handle if sane_exit was called since
1 parent f15b99c commit 659131a

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

_sane.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ typedef struct {
5252

5353
static PyTypeObject SaneDev_Type;
5454

55+
static int g_sane_initialized = 0;
56+
5557

5658
/* Raise a SANE exception */
5759
static PyObject *
@@ -66,7 +68,7 @@ PySane_Error(SANE_Status st)
6668
static void
6769
SaneDev_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
}

0 commit comments

Comments
 (0)