fixed segmentation faults in pie.c when sane_init/sane_exit called more than once

merge-requests/1/head
Simon Munton 2003-02-23 13:32:52 +00:00
rodzic 711f602c76
commit 0423675807
2 zmienionych plików z 20 dodań i 7 usunięć

Wyświetl plik

@ -1,3 +1,7 @@
2003-02-23 Simon Munton <simon@munton.demon.co.uk>
* backend/pie.c: fixed segmentation faults when sane_init/sane_exit is
run more than once.
2003-02-23 Stéphane Voltz <svoltz@wanadoo.fr> 2003-02-23 Stéphane Voltz <svoltz@wanadoo.fr>
* backend/umax_pp_low.c backend/umax_pp_low.c: Added global vars reset. * backend/umax_pp_low.c backend/umax_pp_low.c: Added global vars reset.

Wyświetl plik

@ -43,6 +43,10 @@
If you do not wish that, delete this exception notice. */ If you do not wish that, delete this exception notice. */
/* /*
* 22-2-2003 set devlist to NULL in sane_exit()
* set first_dev to NULL in sane_exit()
* eliminated num_devices
*
* 23-7-2002 added TL_X > BR_X, TL_Y > BR_Y check in sane_start * 23-7-2002 added TL_X > BR_X, TL_Y > BR_Y check in sane_start
* *
* 17-9-2001 changed ADLIB to AdLib as the comparison is case sensitive and * 17-9-2001 changed ADLIB to AdLib as the comparison is case sensitive and
@ -330,9 +334,8 @@ static const SANE_Range percentage_range_100 = {
0 << SANE_FIXED_SCALE_SHIFT /* quantization */ 0 << SANE_FIXED_SCALE_SHIFT /* quantization */
}; };
static int num_devices; static Pie_Device *first_dev = NULL;
static Pie_Device *first_dev; static Pie_Scanner *first_handle = NULL;
static Pie_Scanner *first_handle;
static const SANE_Device **devlist = NULL; static const SANE_Device **devlist = NULL;
@ -1217,7 +1220,6 @@ attach_scanner (const char *devicename, Pie_Device ** devp)
#endif #endif
++num_devices;
dev->next = first_dev; dev->next = first_dev;
first_dev = dev; first_dev = dev;
@ -2975,9 +2977,12 @@ sane_exit (void)
free (dev); free (dev);
} }
first_dev = NULL;
if (devlist) if (devlist)
{ {
free (devlist); free (devlist);
devlist = NULL;
} }
} }
@ -2993,12 +2998,16 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only)
DBG (DBG_sane_init, "sane_get_devices\n"); DBG (DBG_sane_init, "sane_get_devices\n");
i = 0;
for (dev = first_dev; dev; dev = dev->next)
i++;
if (devlist) if (devlist)
{ {
free (devlist); free (devlist);
} }
devlist = malloc ((num_devices + 1) * sizeof (devlist[0])); devlist = malloc ((i + 1) * sizeof (devlist[0]));
if (!devlist) if (!devlist)
{ {
return SANE_STATUS_NO_MEM; return SANE_STATUS_NO_MEM;
@ -3006,12 +3015,12 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only)
i = 0; i = 0;
for (dev = first_dev; i < num_devices; dev = dev->next) for (dev = first_dev; dev; dev = dev->next)
{ {
devlist[i++] = &dev->sane; devlist[i++] = &dev->sane;
} }
devlist[i++] = 0; devlist[i] = NULL;
*device_list = devlist; *device_list = devlist;