Issue #2087 - Issues discovered by coverity scan

Add missing fclose invocations and fix copy-paste issue.

This issues has been discovered by coverity scan proceeded by Red Hat.

Fixed some mistakes in the patch and added more fclose() (Mitch)

(cherry picked from commit 56c8f8320d)
This commit is contained in:
Josef Ridky 2018-08-23 10:05:34 +02:00 committed by Michael Natterer
parent 0f88830a00
commit 2987f012f9
6 changed files with 69 additions and 9 deletions

View File

@ -361,6 +361,7 @@ load_image (const gchar *file,
{
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("EOF or error while reading image header"));
fclose (fp);
return -1;
}
@ -381,6 +382,7 @@ load_image (const gchar *file,
{
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("EOF or error while reading image header"));
fclose (fp);
return -1;
}
@ -389,6 +391,7 @@ load_image (const gchar *file,
{
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("is not a CEL image file"));
fclose (fp);
return -1;
}
@ -403,6 +406,7 @@ load_image (const gchar *file,
default:
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("illegal bpp value in image: %hhu"), bpp);
fclose (fp);
return -1;
}
@ -419,6 +423,7 @@ load_image (const gchar *file,
_("illegal image dimensions: width: %d, horizontal offset: "
"%d, height: %d, vertical offset: %d"),
width, offx, height, offy);
fclose (fp);
return -1;
}
@ -469,6 +474,7 @@ load_image (const gchar *file,
{
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("EOF or error while reading image data"));
fclose (fp);
return -1;
}
@ -505,6 +511,7 @@ load_image (const gchar *file,
{
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("EOF or error while reading image data"));
fclose (fp);
return -1;
}
@ -530,6 +537,7 @@ load_image (const gchar *file,
{
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("EOF or error while reading image data"));
fclose (fp);
return -1;
}
@ -547,6 +555,7 @@ load_image (const gchar *file,
default:
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Unsupported bit depth (%d)!"), bpp);
fclose (fp);
return -1;
}

View File

@ -366,6 +366,7 @@ load_image (const gchar *filename,
if (! ReadOK (fd, buf, 6))
{
g_message ("Error reading magic number");
fclose (fd);
return -1;
}
@ -373,6 +374,7 @@ load_image (const gchar *filename,
{
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
"%s", _("This is not a GIF file"));
fclose (fd);
return -1;
}
@ -382,12 +384,14 @@ load_image (const gchar *filename,
if ((strcmp (version, "87a") != 0) && (strcmp (version, "89a") != 0))
{
g_message ("Bad version number, not '87a' or '89a'");
fclose (fd);
return -1;
}
if (! ReadOK (fd, buf, 7))
{
g_message ("Failed to read screen descriptor");
fclose (fd);
return -1;
}
@ -405,6 +409,7 @@ load_image (const gchar *filename,
&GifScreen.GrayScale))
{
g_message ("Error reading global colormap");
fclose (fd);
return -1;
}
}
@ -422,12 +427,14 @@ load_image (const gchar *filename,
if (! ReadOK (fd, &c, 1))
{
g_message ("EOF / read error on image data");
fclose (fd);
return image_ID; /* will be -1 if failed on first image! */
}
if (c == ';')
{
/* GIF terminator */
fclose (fd);
return image_ID;
}
@ -437,6 +444,7 @@ load_image (const gchar *filename,
if (! ReadOK (fd, &c, 1))
{
g_message ("EOF / read error on extension function code");
fclose (fd);
return image_ID; /* will be -1 if failed on first image! */
}
@ -456,6 +464,7 @@ load_image (const gchar *filename,
if (! ReadOK (fd, buf, 9))
{
g_message ("Couldn't read left/top/width/height");
fclose (fd);
return image_ID; /* will be -1 if failed on first image! */
}
@ -468,6 +477,7 @@ load_image (const gchar *filename,
if (! ReadColorMap (fd, bitPixel, localColorMap, &grayScale))
{
g_message ("Error reading local colormap");
fclose (fd);
return image_ID; /* will be -1 if failed on first image! */
}
@ -515,6 +525,8 @@ load_image (const gchar *filename,
break;
}
fclose (fd);
return image_ID;
}

View File

@ -826,6 +826,7 @@ load_image (const gchar *filename,
{
g_message (_("'%s':\nCould not read header (ftell == %ld)"),
gimp_filename_to_utf8 (filename), ftell (fp));
fclose (fp);
return -1;
}
@ -833,6 +834,7 @@ load_image (const gchar *filename,
{
g_message (_("'%s':\nNo image width specified"),
gimp_filename_to_utf8 (filename));
fclose (fp);
return -1;
}
@ -840,6 +842,7 @@ load_image (const gchar *filename,
{
g_message (_("'%s':\nImage width is larger than GIMP can handle"),
gimp_filename_to_utf8 (filename));
fclose (fp);
return -1;
}
@ -847,6 +850,7 @@ load_image (const gchar *filename,
{
g_message (_("'%s':\nNo image height specified"),
gimp_filename_to_utf8 (filename));
fclose (fp);
return -1;
}
@ -854,6 +858,7 @@ load_image (const gchar *filename,
{
g_message (_("'%s':\nImage height is larger than GIMP can handle"),
gimp_filename_to_utf8 (filename));
fclose (fp);
return -1;
}
@ -861,6 +866,7 @@ load_image (const gchar *filename,
{
g_message (_("'%s':\nNo image data type specified"),
gimp_filename_to_utf8 (filename));
fclose (fp);
return -1;
}

View File

@ -671,6 +671,7 @@ load_image (const gchar *filename,
{
g_set_error (error, 0, 0, _("'%s' is not a valid X cursor."),
gimp_filename_to_utf8 (filename));
fclose (fp);
return -1;
}
@ -683,6 +684,7 @@ load_image (const gchar *filename,
g_set_error (error, 0, 0,
_("Frame %d of '%s' is too wide for an X cursor."),
i + 1, gimp_filename_to_utf8 (filename));
fclose (fp);
return -1;
}
if (imagesp->images[i]->height > MAX_LOAD_DIMENSION)
@ -690,6 +692,7 @@ load_image (const gchar *filename,
g_set_error (error, 0, 0,
_("Frame %d of '%s' is too high for an X cursor."),
i + 1, gimp_filename_to_utf8 (filename));
fclose (fp);
return -1;
}
}
@ -706,7 +709,10 @@ load_image (const gchar *filename,
gimp_image_set_filename (image_ID, filename);
if (! set_hotspot_to_parasite (image_ID))
{
fclose (fp);
return -1;
}
/* Temporary buffer */
tmppixel = g_new (guint32, img_width * img_height);
@ -730,7 +736,10 @@ load_image (const gchar *filename,
framename = make_framename (imagesp->images[i]->size, delay,
DISPLAY_DIGIT (imagesp->nimage), error);
if (! framename)
{
fclose (fp);
return -1;
}
layer_ID = gimp_layer_new (image_ID, framename, width, height,
GIMP_RGBA_IMAGE,
@ -782,6 +791,7 @@ load_image (const gchar *filename,
parasiteName[commentsp->comments[i]->comment_type -1]))
{
DM_XMC ("Failed to write %ith comment.\n", i);
fclose (fp);
return -1;
}
}
@ -868,6 +878,7 @@ load_thumbnail (const gchar *filename,
g_set_error (error, 0, 0,
"'%s' seems to have an incorrect toc size.",
gimp_filename_to_utf8 (filename));
fclose (fp);
return -1;
}
positions = g_malloc (ntoc * sizeof (guint32));
@ -906,6 +917,7 @@ load_thumbnail (const gchar *filename,
g_set_error (error, 0, 0,
_("there is no image chunk in \"%s\"."),
gimp_filename_to_utf8 (filename));
fclose (fp);
return -1;
}
@ -946,6 +958,7 @@ load_thumbnail (const gchar *filename,
g_set_error (error, 0, 0,
_("'%s' is too wide for an X cursor."),
gimp_filename_to_utf8 (filename));
fclose (fp);
return -1;
}
@ -954,6 +967,7 @@ load_thumbnail (const gchar *filename,
g_set_error (error, 0, 0,
_("'%s' is too high for an X cursor."),
gimp_filename_to_utf8 (filename));
fclose (fp);
return -1;
}
@ -1497,6 +1511,7 @@ save_image (const gchar *filename,
if (!imagesp)
{
DM_XMC ("Failed to XcursorImagesCreate!\n");
fclose (fp);
return FALSE;
}
imagesp->nimage = nlayers;
@ -1541,6 +1556,7 @@ save_image (const gchar *filename,
_("Frame '%s' is too wide. Please reduce to no more than %dpx."),
gimp_any_to_utf8 (framename, -1, NULL),
MAX_SAVE_DIMENSION);
fclose (fp);
return FALSE;
}
@ -1550,6 +1566,7 @@ save_image (const gchar *filename,
_("Frame '%s' is too high. Please reduce to no more than %dpx."),
gimp_any_to_utf8 (framename, -1, NULL),
MAX_SAVE_DIMENSION);
fclose (fp);
return FALSE;
}
@ -1558,6 +1575,7 @@ save_image (const gchar *filename,
g_set_error (error, 0, 0,
_("Width and/or height of frame '%s' is zero!"),
gimp_any_to_utf8 (framename, -1, NULL));
fclose (fp);
return FALSE;
}
@ -1578,6 +1596,7 @@ save_image (const gchar *filename,
if (!imagesp->images[i])
{
DM_XMC ("Failed to XcursorImageCreate.\n");
fclose (fp);
return FALSE;
}
imagesp->images[i]->pixels[0] = 0x0;
@ -1600,6 +1619,7 @@ save_image (const gchar *filename,
"Try to change the hot spot position, "
"layer geometry or export without auto-crop."),
gimp_any_to_utf8 (framename, -1, NULL));
fclose (fp);
return FALSE;
}
}
@ -1633,6 +1653,7 @@ save_image (const gchar *filename,
if (!imagesp->images[i])
{
DM_XMC ("Failed to XcursorImageCreate.\n");
fclose (fp);
return FALSE;
}
/*
@ -1683,7 +1704,10 @@ save_image (const gchar *filename,
DISPLAY_DIGIT (imagesp->nimage),
error);
if (! framename)
{
fclose (fp);
return FALSE;
}
gimp_item_set_name (orig_layers[nlayers - 1 - i], framename);
g_free (framename);
@ -1742,6 +1766,7 @@ save_image (const gchar *filename,
{
DM_XMC ("Failed to XcursorFileSave.\t%p\t%p\t%p\n",
fp, commentsp, imagesp);
fclose (fp);
return FALSE;
}
@ -1751,6 +1776,7 @@ save_image (const gchar *filename,
if (! XcursorFileSaveImages (fp, imagesp))
{
DM_XMC ("Failed to XcursorFileSaveImages.\t%p\t%p\n", fp, imagesp);
fclose (fp);
return FALSE;
}
}

View File

@ -505,9 +505,14 @@ load_image (const gchar *filename,
fli_read_header (file, &fli_header);
if (fli_header.magic == NO_HEADER)
{
fclose (file);
return -1;
}
else
{
fseek (file, 128, SEEK_SET);
}
/*
* Fix parameters
@ -528,11 +533,13 @@ load_image (const gchar *filename,
if (to_frame < 1)
{
/* nothing to do ... */
fclose (file);
return -1;
}
if (from_frame >= fli_header.frames)
{
/* nothing to do ... */
fclose (file);
return -1;
}
if (to_frame>fli_header.frames)

View File

@ -125,7 +125,7 @@ def whirl_pinch(image, drawable, whirl, pinch, radius):
if cx >= 0: ix = int(cx)
else: ix = -(int(-cx) + 1)
if cy >= 0: iy = int(cy)
else: iy = -(int(-cx) + 1)
else: iy = -(int(-cy) + 1)
pixel[0] = pft.get_pixel(ix, iy)
pixel[1] = pft.get_pixel(ix+1, iy)
pixel[2] = pft.get_pixel(ix, iy+1)