Merge branch 'escl-Memory-and-file-handle-leak' into 'master'

Escl memory and file handle leak

See merge request sane-project/backends!296
merge-requests/317/merge
Olaf Meeuwissen 2020-01-08 11:28:08 +00:00
commit 8b611a252d
5 zmienionych plików z 51 dodań i 1 usunięć

Wyświetl plik

@ -475,7 +475,11 @@ sane_cancel(SANE_Handle h)
{
DBG (10, "escl sane_cancel\n");
escl_sane_t *handler = h;
if (handler->scanner->tmp)
{
fclose(handler->scanner->tmp);
handler->scanner->tmp = NULL;
}
handler->cancel = SANE_TRUE;
escl_scanner(handler->name, handler->result);
}

Wyświetl plik

@ -148,6 +148,10 @@ get_JPEG_data(capabilities_t *scanner, int *w, int *h, int *bps)
jpeg_destroy_decompress(&cinfo);
if (surface != NULL)
free(surface);
if (scanner->tmp) {
fclose(scanner->tmp);
scanner->tmp = NULL;
}
return (SANE_STATUS_INVAL);
}
jpeg_create_decompress(&cinfo);
@ -160,6 +164,10 @@ get_JPEG_data(capabilities_t *scanner, int *w, int *h, int *bps)
if (surface == NULL) {
jpeg_destroy_decompress(&cinfo);
fseek(scanner->tmp, start, SEEK_SET);
if (scanner->tmp) {
fclose(scanner->tmp);
scanner->tmp = NULL;
}
return (SANE_STATUS_NO_MEM);
}
lineSize = cinfo.output_width * cinfo.output_components;

Wyświetl plik

@ -29,6 +29,12 @@
#include <curl/curl.h>
#ifdef PATH_MAX
# undef PATH_MAX
#endif
#define PATH_MAX 4096
struct uploading
{
const char *read_data;

Wyświetl plik

@ -38,6 +38,10 @@ get_PNG_data(capabilities_t *scanner, int *w, int *h, int *components)
if (!png_check_sig (magic, sizeof (magic)))
{
fprintf(stderr,"PNG error: is not a valid PNG image!\n");
if (scanner->tmp) {
fclose(scanner->tmp);
scanner->tmp = NULL;
}
return (SANE_STATUS_INVAL);
}
// create a png read struct
@ -45,6 +49,10 @@ get_PNG_data(capabilities_t *scanner, int *w, int *h, int *components)
(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr)
{
if (scanner->tmp) {
fclose(scanner->tmp);
scanner->tmp = NULL;
}
return (SANE_STATUS_INVAL);
}
// create a png info struct
@ -52,6 +60,10 @@ get_PNG_data(capabilities_t *scanner, int *w, int *h, int *components)
if (!info_ptr)
{
png_destroy_read_struct (&png_ptr, NULL, NULL);
if (scanner->tmp) {
fclose(scanner->tmp);
scanner->tmp = NULL;
}
return (SANE_STATUS_INVAL);
}
// initialize the setjmp for returning properly after a libpng
@ -62,6 +74,10 @@ get_PNG_data(capabilities_t *scanner, int *w, int *h, int *components)
if (texels)
free (texels);
fprintf(stderr,"PNG read error.\n");
if (scanner->tmp) {
fclose(scanner->tmp);
scanner->tmp = NULL;
}
return (SANE_STATUS_INVAL);
}
// setup libpng for using standard C fread() function
@ -83,6 +99,10 @@ get_PNG_data(capabilities_t *scanner, int *w, int *h, int *components)
else if (color_type != PNG_COLOR_TYPE_RGB && color_type != PNG_COLOR_TYPE_RGB_ALPHA)
{
fprintf(stderr,"PNG format not supported.\n");
if (scanner->tmp) {
fclose(scanner->tmp);
scanner->tmp = NULL;
}
return (SANE_STATUS_INVAL);
}
if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)

Wyświetl plik

@ -37,6 +37,10 @@ get_TIFF_data(capabilities_t *scanner, int *w, int *h, int *components)
tif = TIFFFdOpen(fileno(scanner->tmp), "temp", "r");
if (!tif) {
fprintf(stderr, "Can not open, or not a TIFF file.\n");
if (scanner->tmp) {
fclose(scanner->tmp);
scanner->tmp = NULL;
}
return (SANE_STATUS_INVAL);
}
@ -47,12 +51,20 @@ get_TIFF_data(capabilities_t *scanner, int *w, int *h, int *components)
if (raster != NULL)
{
fprintf(stderr, "Memory allocation problem.\n");
if (scanner->tmp) {
fclose(scanner->tmp);
scanner->tmp = NULL;
}
return (SANE_STATUS_INVAL);
}
if (!TIFFReadRGBAImage(tif, width, height, (uint32 *)raster, 0))
{
fprintf(stderr, "Problem reading image data.\n");
if (scanner->tmp) {
fclose(scanner->tmp);
scanner->tmp = NULL;
}
return (SANE_STATUS_INVAL);
}
*w = (int)width;