Verify allocation and add debug.

merge-requests/313/head
thierry1970 2020-01-23 12:20:48 +01:00
rodzic 51b9883603
commit a0845a8322
1 zmienionych plików z 75 dodań i 5 usunięć

Wyświetl plik

@ -90,6 +90,7 @@ SANE_Status
escl_device_add(int port_nb, const char *model_name, char *ip_address, char *type)
{
char tmp[PATH_MAX] = { 0 };
char *model = NULL;
ESCL_Device *current = NULL;
DBG (10, "escl_device_add\n");
for (current = list_devices_primary; current; current = current->next) {
@ -98,19 +99,32 @@ escl_device_add(int port_nb, const char *model_name, char *ip_address, char *typ
return (SANE_STATUS_GOOD);
}
current = malloc(sizeof(*current));
if (current == NULL)
return (SANE_STATUS_NO_MEM);
if (current == NULL) {
DBG (10, "New device allocation failure.\n");
return (SANE_STATUS_NO_MEM);
}
memset(current, 0, sizeof(*current));
current->port_nb = port_nb;
if (strcmp(type, "_uscan._tcp") != 0 && strcmp(type, "http") != 0) {
snprintf(tmp, sizeof(tmp), "%s SSL", model_name);
current->model_name = strdup(tmp);
}
else
current->model_name = strdup(model_name);
model = (tmp[0] != 0 ? tmp : model_name);
current->model_name = strdup(tmp);
if (!current->model_name) {
DBG (10, "Modele name allocation failure.\n");
return (SANE_STATUS_NO_MEM);
}
current->ip_address = strdup(ip_address);
if (!current->ip_address) {
DBG (10, "Ip Address allocation failure.\n");
return (SANE_STATUS_NO_MEM);
}
current->type = strdup(type);
if (!current->type) {
DBG (10, "Type connection allocation failure.\n");
return (SANE_STATUS_NO_MEM);
}
return escl_add_in_list(current);
}
@ -158,9 +172,25 @@ convertFromESCLDev(ESCL_Device *cdev)
snprintf(tmp, sizeof(tmp), "https://%s:%d", cdev->ip_address, cdev->port_nb);
DBG( 1, "Escl add device : %s\n", tmp);
sdev->name = strdup(tmp);
if (!sdev->name) {
DBG (10, "Name allocation failure.\n");
return (SANE_STATUS_NO_MEM);
}
sdev->model = strdup(cdev->model_name);
if (!sdev->model) {
DBG (10, "Model allocation failure.\n");
return (SANE_STATUS_NO_MEM);
}
sdev->vendor = strdup("ESCL");
if (!sdev->vendor) {
DBG (10, "Vendor allocation failure.\n");
return (SANE_STATUS_NO_MEM);
}
sdev->type = strdup("flatbed scanner");
if (!sdev->type) {
DBG (10, "Scanner Type allocation failure.\n");
return (SANE_STATUS_NO_MEM);
}
return (sdev);
}
@ -231,12 +261,20 @@ attach_one_config(SANEI_Config __sane_unused__ *config, const char *line)
if (strncmp(line, "[device]", 8) == 0) {
count = 0;
escl_device = (ESCL_Device*)calloc(1, sizeof(ESCL_Device));
if (!escl_device) {
DBG (10, "New Escl_Device allocation failure.\n");
return (SANE_STATUS_NO_MEM);
}
}
if (strncmp(line, "ip", 2) == 0) {
const char *ip_space = sanei_config_skip_whitespace(line + 2);
if (escl_device != NULL && ip_space != NULL) {
count++;
escl_device->ip_address = strdup(ip_space);
if (!escl_device->ip_address) {
DBG (10, "Ip Address allocation failure.\n");
return (SANE_STATUS_NO_MEM);
}
}
}
if (sscanf(line, "port %i", &port) == 1 && port != 0) {
@ -251,6 +289,10 @@ attach_one_config(SANEI_Config __sane_unused__ *config, const char *line)
if (escl_device != NULL && model_space != NULL) {
count++;
escl_device->model_name = strdup(model_space);
if (!escl_device->model_name) {
DBG (10, "Modele Name allocation failure.\n");
return (SANE_STATUS_NO_MEM);
}
}
}
if (strncmp(line, "type", 4) == 0) {
@ -258,6 +300,10 @@ attach_one_config(SANEI_Config __sane_unused__ *config, const char *line)
if (escl_device != NULL && type_space != NULL) {
count++;
escl_device->type = strdup(type_space);
if (!escl_device->type) {
DBG (10, "Scanner Type allocation failure.\n");
return (SANE_STATUS_NO_MEM);
}
}
}
if (count == 4)
@ -356,8 +402,16 @@ init_options(SANE_String_Const name, escl_sane_t *s)
s->opt[OPT_MODE].constraint_type = SANE_CONSTRAINT_STRING_LIST;
s->opt[OPT_MODE].constraint.string_list = s->scanner->ColorModes;
s->val[OPT_MODE].s = (char *)strdup(s->scanner->ColorModes[0]);
if (!s->val[OPT_MODE].s) {
DBG (10, "Color Mode Default allocation failure.\n");
return (SANE_STATUS_NO_MEM);
}
s->opt[OPT_MODE].size = max_string_size(s->scanner->ColorModes);
s->scanner->default_color = (char *)strdup(s->scanner->ColorModes[0]);
if (!s->scanner->default_color) {
DBG (10, "Color Mode Default allocation failure.\n");
return (SANE_STATUS_NO_MEM);
}
s->opt[OPT_RESOLUTION].name = SANE_NAME_SCAN_RESOLUTION;
s->opt[OPT_RESOLUTION].title = SANE_TITLE_SCAN_RESOLUTION;
@ -451,6 +505,10 @@ sane_open(SANE_String_Const name, SANE_Handle *h)
if (handler == NULL)
return (SANE_STATUS_NO_MEM);
handler->name = strdup(name);
if (!handler->name) {
DBG (10, "Handle Name allocation failure.\n");
return (SANE_STATUS_NO_MEM);
}
handler->scanner = escl_capabilities(name, &status);
if (status != SANE_STATUS_GOOD)
return (status);
@ -594,6 +652,10 @@ sane_control_option(SANE_Handle h, SANE_Int n, SANE_Action a, void *v, SANE_Int
if (handler->val[n].s)
free (handler->val[n].s);
handler->val[n].s = strdup (v);
if (!handler->val[n].s) {
DBG (10, "OPT_MODE allocation failure.\n");
return (SANE_STATUS_NO_MEM);
}
if (i)
*i |= SANE_INFO_RELOAD_PARAMS | SANE_INFO_RELOAD_OPTIONS | SANE_INFO_INEXACT;
break;
@ -641,6 +703,10 @@ sane_start(SANE_Handle h)
handler->scanner->default_color = strdup("Grayscale8");
else
handler->scanner->default_color = strdup("RGB24");
if (!handler->scanner->default_color) {
DBG (10, "Default Color allocation failure.\n");
return (SANE_STATUS_NO_MEM);
}
for (i = 1; i < handler->scanner->SupportedResolutionsSize; i++)
{
if (val > handler->scanner->SupportedResolutions[i])
@ -656,6 +722,10 @@ sane_start(SANE_Handle h)
else
handler->scanner->default_color = strdup("RGB24");
}
if (!handler->scanner->default_color) {
DBG (10, "Default Color allocation failure.\n");
return (SANE_STATUS_NO_MEM);
}
handler->result = escl_newjob(handler->scanner, handler->name, &status);
if (status != SANE_STATUS_GOOD)
return (status);