plugged memleaks and added some sanity checks.

2003-09-28  Sven Neumann  <sven@gimp.org>

	* app/core/gimpscanconvert.c (gimp_scan_convert_free)
	(gimp_scan_convert_finish): plugged memleaks and added some sanity
	checks.

	* app/base/pixel-region.c
	* app/core/gimpdrawable-preview.c: removed trailing whitespace.

	* app/tools/gimpdrawtool.c (gimp_draw_tool_on_vectors_curve):
	gimp_stroke_nearest_point_get() doesn't set cur_pos when there are
	no strokes; don't use the uninitialized variable.
This commit is contained in:
Sven Neumann 2003-09-28 20:13:59 +00:00 committed by Sven Neumann
parent 515dfaaa7b
commit 30a4f72166
5 changed files with 101 additions and 91 deletions

View File

@ -1,3 +1,16 @@
2003-09-28 Sven Neumann <sven@gimp.org>
* app/core/gimpscanconvert.c (gimp_scan_convert_free)
(gimp_scan_convert_finish): plugged memleaks and added some sanity
checks.
* app/base/pixel-region.c
* app/core/gimpdrawable-preview.c: removed trailing whitespace.
* app/tools/gimpdrawtool.c (gimp_draw_tool_on_vectors_curve):
gimp_stroke_nearest_point_get() doesn't set cur_pos when there are
no strokes; don't use the uninitialized variable.
2003-09-28 Ville Pätsi <drc@gimp.org>
* themes/Default/images/stock-join-round-16.png

View File

@ -36,7 +36,7 @@
static gint get_portion_width (PixelRegionIterator *PRI);
static gint get_portion_height (PixelRegionIterator *PRI);
static PixelRegionIterator * pixel_regions_configure (PixelRegionIterator *PRI);
static void pixel_region_configure (PixelRegionHolder *PRH,
static void pixel_region_configure (PixelRegionHolder *PRH,
PixelRegionIterator *PRI);
@ -44,12 +44,12 @@ static void pixel_region_configure (PixelRegionHolder *PRH,
/* Function definitions */
void
pixel_region_init (PixelRegion *PR,
TileManager *tiles,
gint x,
gint y,
gint w,
gint h,
pixel_region_init (PixelRegion *PR,
TileManager *tiles,
gint x,
gint y,
gint w,
gint h,
gboolean dirty)
{
PR->tiles = tiles;
@ -65,10 +65,10 @@ pixel_region_init (PixelRegion *PR,
}
void
pixel_region_resize (PixelRegion *PR,
gint x,
gint y,
gint w,
pixel_region_resize (PixelRegion *PR,
gint x,
gint y,
gint w,
gint h)
{
/* If the data is non-null, data is contiguous--need to advance */
@ -87,10 +87,10 @@ pixel_region_resize (PixelRegion *PR,
/* request that tiles within a region be fetched asynchronously */
void
pixel_region_get_async (PixelRegion *PR,
gint ulx,
gint uly,
gint lrx,
pixel_region_get_async (PixelRegion *PR,
gint ulx,
gint uly,
gint lrx,
gint lry)
{
gint x;
@ -103,11 +103,11 @@ pixel_region_get_async (PixelRegion *PR,
void
pixel_region_get_row (PixelRegion *PR,
gint x,
gint y,
gint w,
guchar *data,
pixel_region_get_row (PixelRegion *PR,
gint x,
gint y,
gint w,
guchar *data,
gint subsample)
{
Tile *tile;
@ -130,23 +130,23 @@ pixel_region_get_row (PixelRegion *PR,
{
read_pixel_data (PR->tiles, x, y, end-1, y, data, tilebpp);
}
else
else
{
while (x < end)
{
tile = tile_manager_get_tile (PR->tiles, x, y, TRUE, FALSE);
tile_data = tile_data_pointer (tile, x % TILE_WIDTH, y % TILE_HEIGHT);
npixels = tile_ewidth (tile) - (x % TILE_WIDTH);
if ((x + npixels) > end) /* make sure we don't write past the end */
npixels = end - x;
boundary = x + npixels;
for ( ; x < boundary; x += subsample)
{
for (b = 0; b < tilebpp; b++)
*data++ = tile_data[b];
tile_data += inc;
}
tile_release (tile, FALSE);
@ -155,10 +155,10 @@ pixel_region_get_row (PixelRegion *PR,
}
void
pixel_region_set_row (PixelRegion *PR,
gint x,
gint y,
gint w,
pixel_region_set_row (PixelRegion *PR,
gint x,
gint y,
gint w,
guchar *data)
{
gint end;
@ -174,11 +174,11 @@ pixel_region_set_row (PixelRegion *PR,
void
pixel_region_get_col (PixelRegion *PR,
gint x,
gint y,
gint h,
guchar *data,
pixel_region_get_col (PixelRegion *PR,
gint x,
gint y,
gint h,
guchar *data,
gint subsample)
{
Tile *tile;
@ -220,10 +220,10 @@ pixel_region_get_col (PixelRegion *PR,
void
pixel_region_set_col (PixelRegion *PR,
gint x,
gint y,
gint h,
pixel_region_set_col (PixelRegion *PR,
gint x,
gint y,
gint h,
guchar *data)
{
gint tilebpp;
@ -248,7 +248,7 @@ pixel_region_has_alpha (PixelRegion *PR)
}
PixelRegionIterator *
pixel_regions_register (gint num_regions,
pixel_regions_register (gint num_regions,
...)
{
PixelRegion *PR;
@ -323,7 +323,7 @@ pixel_regions_process (PixelRegionIterator *PRI)
*/
PRH->PR->process_count++;
/* Unref the last referenced tile if the underlying region
/* Unref the last referenced tile if the underlying region
is a tile manager */
if (PRH->PR->tiles)
{
@ -367,7 +367,7 @@ pixel_regions_process_stop (PixelRegionIterator *PRI)
*/
PRH->PR->process_count++;
/* Unref the last referenced tile if the underlying region
/* Unref the last referenced tile if the underlying region
is a tile manager */
if (PRH->PR->tiles)
{
@ -399,8 +399,8 @@ get_portion_height (PixelRegionIterator *PRI)
gint min_height = G_MAXINT;
gint height;
/* Find the minimum height to the next vertical tile
* (in the case of a tile manager) or to the end of the
/* Find the minimum height to the next vertical tile
* (in the case of a tile manager) or to the end of the
* pixel region (in the case of no tile manager)
*/
@ -417,8 +417,8 @@ get_portion_height (PixelRegionIterator *PRI)
if (PRH->PR->tiles)
{
height = TILE_HEIGHT - (PRH->PR->y % TILE_HEIGHT);
height = CLAMP (height,
0,
height = CLAMP (height,
0,
(PRI->region_height - (PRH->PR->y - PRH->starty)));
}
else
@ -441,8 +441,8 @@ get_portion_width (PixelRegionIterator *PRI)
gint min_width = G_MAXINT;
gint width;
/* Find the minimum width to the next vertical tile
* (in the case of a tile manager) or to the end of
/* Find the minimum width to the next vertical tile
* (in the case of a tile manager) or to the end of
* the pixel region (in the case of no tile manager)
*/
@ -459,8 +459,8 @@ get_portion_width (PixelRegionIterator *PRI)
if (PRH->PR->tiles)
{
width = TILE_WIDTH - (PRH->PR->x % TILE_WIDTH);
width = CLAMP (width,
0,
width = CLAMP (width,
0,
(PRI->region_width - (PRH->PR->x - PRH->startx)));
}
else
@ -518,7 +518,7 @@ pixel_regions_configure (PixelRegionIterator *PRI)
static void
pixel_region_configure (PixelRegionHolder *PRH,
pixel_region_configure (PixelRegionHolder *PRH,
PixelRegionIterator *PRI)
{
/* Configure the rowstride and data pointer for the pixel region
@ -527,18 +527,18 @@ pixel_region_configure (PixelRegionHolder *PRH,
*/
if (PRH->PR->tiles)
{
PRH->PR->curtile = tile_manager_get_tile (PRH->PR->tiles,
PRH->PR->x,
PRH->PR->y,
TRUE,
PRH->PR->curtile = tile_manager_get_tile (PRH->PR->tiles,
PRH->PR->x,
PRH->PR->y,
TRUE,
PRH->PR->dirty);
PRH->PR->offx = PRH->PR->x % TILE_WIDTH;
PRH->PR->offy = PRH->PR->y % TILE_HEIGHT;
PRH->PR->rowstride = tile_ewidth (PRH->PR->curtile) * PRH->PR->bytes;
PRH->PR->data = tile_data_pointer (PRH->PR->curtile,
PRH->PR->offx,
PRH->PR->data = tile_data_pointer (PRH->PR->curtile,
PRH->PR->offx,
PRH->PR->offy);
}
else

View File

@ -206,7 +206,7 @@ gimp_drawable_preview_private (GimpDrawable *drawable,
TempBuf *ret_buf;
if (drawable->preview_valid &&
(ret_buf = gimp_preview_cache_get (&drawable->preview_cache,
(ret_buf = gimp_preview_cache_get (&drawable->preview_cache,
width, height)))
{
/* The easy way */
@ -301,9 +301,9 @@ gimp_drawable_preview_scale (GimpImageBaseType type,
gint subsample)
{
#define EPSILON 0.000001
guchar *src, *s;
guchar *src, *s;
guchar *dest, *d;
gdouble *row, *r;
gdouble *row, *r;
gint destwidth;
gint src_row, src_col;
gint bytes, b;
@ -352,22 +352,23 @@ gimp_drawable_preview_scale (GimpImageBaseType type,
}
else
{
src_col ++;
src_col++;
x_frac[i] = src_col - x_last;
}
x_last += x_frac[i];
}
/* counters... */
src_row = 0;
y_cum = (double) src_row;
y_cum = (gdouble) src_row;
y_last = y_cum;
pixel_region_get_row (srcPR,
0,
src_row * subsample,
orig_width * subsample,
src,
pixel_region_get_row (srcPR,
0,
src_row * subsample,
orig_width * subsample,
src,
subsample);
/* Scale the selected region */
@ -385,7 +386,7 @@ gimp_drawable_preview_scale (GimpImageBaseType type,
}
else
{
src_row ++;
src_row++;
y_frac = src_row - y_last;
advance_dest = FALSE;
}
@ -460,11 +461,11 @@ gimp_drawable_preview_scale (GimpImageBaseType type,
}
else
{
pixel_region_get_row (srcPR,
0,
src_row * subsample,
orig_width * subsample,
src,
pixel_region_get_row (srcPR,
0,
src_row * subsample,
orig_width * subsample,
src,
subsample);
}
}

View File

@ -74,18 +74,9 @@ gimp_scan_convert_new (guint width,
sc = g_new0 (GimpScanConvert, 1);
sc->antialias = antialias;
sc->width = width;
sc->height = height;
sc->got_first = FALSE;
sc->need_closing = FALSE;
sc->have_open = FALSE;
sc->num_nodes = 0;
sc->vpath = NULL;
sc->svp = NULL;
sc->antialias = antialias;
return sc;
}
@ -93,8 +84,13 @@ gimp_scan_convert_new (guint width,
void
gimp_scan_convert_free (GimpScanConvert *sc)
{
art_free (sc->vpath);
art_free (sc->svp);
g_return_if_fail (sc != NULL);
if (sc->vpath)
art_free (sc->vpath);
if (sc->svp)
art_svp_free (sc->svp);
g_free (sc);
}
@ -126,10 +122,10 @@ gimp_scan_convert_add_points (GimpScanConvert *sc,
}
/* We have to compress multiple identical coordinates */
for (i = 0; i < n_points; i++)
{
if (sc->got_first == FALSE ||
if (sc->got_first == FALSE ||
sc->prev.x != points[i].x || sc->prev.y != points[i].y)
{
sc->vpath[sc->num_nodes].code = ((! sc->got_first) || new_polygon) ?
@ -156,7 +152,7 @@ gimp_scan_convert_add_points (GimpScanConvert *sc,
static void
gimp_scan_convert_close_add_points (GimpScanConvert *sc)
{
if (sc->need_closing &&
if (sc->need_closing &&
(sc->prev.x != sc->first.x || sc->prev.y != sc->first.y))
{
sc->vpath = art_renew (sc->vpath, ArtVpath, sc->num_nodes + 2);
@ -298,7 +294,7 @@ gimp_scan_convert_stroke (GimpScanConvert *sc,
dash.offset = dash_offset * width;
dashes = g_new (gdouble, dash_info->len);
for (i=0; i < dash_info->len ; i++)
dashes[i] = width * g_array_index (dash_info, gdouble, i);
@ -452,10 +448,10 @@ gimp_scan_convert_finish (GimpScanConvert *sc)
art_free (pert_vpath);
svp2 = art_svp_uncross (svp);
art_free (svp);
art_svp_free (svp);
svp = art_svp_rewind_uncrossed (svp2, ART_WIND_RULE_ODDEVEN);
art_free (svp2);
art_svp_free (svp2);
sc->svp = svp;
}

View File

@ -1012,7 +1012,7 @@ gimp_draw_tool_on_vectors_curve (GimpDrawTool *draw_tool,
&segment_end,
&cur_pos);
if (cur_dist < min_dist || min_dist < 0)
if (cur_dist < min_dist)
{
min_dist = cur_dist;
min_coords = cur_coords;
@ -1097,7 +1097,7 @@ gimp_draw_tool_on_vectors (GimpDrawTool *draw_tool,
return FALSE;
}
void
gimp_draw_tool_draw_lines (GimpDrawTool *draw_tool,
gdouble *points,