Get rid of small memory leak when using 'scanimage -L'.

DEVEL_2_0_BRANCH-1
Petter Reinholdtsen 2001-02-12 19:31:01 +00:00
rodzic 86ee15cba9
commit 7e318fb164
2 zmienionych plików z 30 dodań i 8 usunięć

Wyświetl plik

@ -178,6 +178,13 @@ struct alias
char *newname;
};
/*
* List of available devices, allocated by sane_get_devices, released
* by sane_exit()
*/
static const SANE_Device **devlist = NULL;
static int devlist_size = 0, devlist_len = 0;
static struct alias *first_alias;
static SANE_Auth_Callback auth_callback;
static struct backend *first_backend;
@ -584,6 +591,18 @@ sane_exit (void)
free(alias->oldname);
free(alias);
}
if (NULL != devlist)
{ /* Release memory allocated by sane_get_devices(). */
int i = 0;
while (devlist[i])
free(devlist[i++]);
free(devlist);
devlist = NULL;
devlist_size = 0;
devlist_len = 0;
}
}
/* Note that a call to get_devices() implies that we'll have to load
@ -594,8 +613,6 @@ sane_exit (void)
SANE_Status
sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only)
{
static int devlist_size = 0, devlist_len = 0;
static const SANE_Device **devlist;
const SANE_Device **be_list;
struct backend *be;
SANE_Status status;

Wyświetl plik

@ -108,6 +108,7 @@
#include "sane/sanei_config.h"
#define V4L_CONFIG_FILE "v4l.conf"
static const SANE_Device ** devlist = NULL;
static int num_devices;
static V4L_Device * first_dev;
static V4L_Scanner * first_handle;
@ -179,6 +180,9 @@ attach (const char *devname, V4L_Device **devp)
{
V4L_Device * q;
if (!devp)
return SANE_STATUS_INVAL;
errno = 0;
q = malloc (sizeof (*q));
@ -199,12 +203,8 @@ attach (const char *devname, V4L_Device **devp)
first_dev = q;
if (devp)
*devp = q;
*devp = q;
return SANE_STATUS_GOOD;
free (q);
return SANE_STATUS_INVAL;
}
@ -626,12 +626,17 @@ sane_exit (void)
free ((void *) dev->sane.name);
free (dev);
}
if (NULL != devlist)
{
free(devlist);
devlist = NULL;
}
}
SANE_Status
sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only)
{
static const SANE_Device ** devlist = 0;
V4L_Device *dev;
int i;