Commit 5fec1a7b4 for imagemagick.org
commit 5fec1a7b4b5e5315510666275edca45f04338f02
Author: Cristy <urban-warrior@imagemagick.org>
Date: Wed Nov 25 19:54:26 2026 -0500
if the cache view couldn't be acquired, the freshly allocated ExceptionInfo was never freed
diff --git a/MagickWand/pixel-iterator.c b/MagickWand/pixel-iterator.c
index 4f5889447..238fff7d1 100644
--- a/MagickWand/pixel-iterator.c
+++ b/MagickWand/pixel-iterator.c
@@ -303,7 +303,10 @@ WandExport PixelIterator *NewPixelIterator(MagickWand *wand)
exception=AcquireExceptionInfo();
view=AcquireVirtualCacheView(image,exception);
if (view == (CacheView *) NULL)
- return((PixelIterator *) NULL);
+ {
+ exception=DestroyExceptionInfo(exception);
+ return((PixelIterator *) NULL);
+ }
iterator=(PixelIterator *) AcquireCriticalMemory(sizeof(*iterator));
(void) memset(iterator,0,sizeof(*iterator));
iterator->id=AcquireWandId();
@@ -409,7 +412,10 @@ WandExport PixelIterator *NewPixelRegionIterator(MagickWand *wand,
exception=AcquireExceptionInfo();
view=AcquireVirtualCacheView(image,exception);
if (view == (CacheView *) NULL)
- return((PixelIterator *) NULL);
+ {
+ exception=DestroyExceptionInfo(exception);
+ return((PixelIterator *) NULL);
+ }
iterator=(PixelIterator *) AcquireCriticalMemory(sizeof(*iterator));
(void) memset(iterator,0,sizeof(*iterator));
iterator->id=AcquireWandId();
@@ -436,52 +442,50 @@ WandExport PixelIterator *NewPixelRegionIterator(MagickWand *wand,
% %
% %
% %
-% P i x e l G e t C u r r e n t I t e r a t o r R o w %
+% R e a d I t e r a t o r R o w %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% PixelGetCurrentIteratorRow() returns the current row as an array of pixel
-% wands from the pixel iterator.
+% ReadIteratorRow() loads the pixels of the current iterator row into the
+% iterator's pixel wands.
%
-% The format of the PixelGetCurrentIteratorRow method is:
+% The format of the ReadIteratorRow method is:
%
-% PixelWand **PixelGetCurrentIteratorRow(PixelIterator *iterator,
+% PixelWand **ReadIteratorRow(PixelIterator *iterator,
% size_t *number_wands)
%
% A description of each parameter follows:
%
% o iterator: the pixel iterator.
%
-% o number_wands: the number of pixel wands.
+% o number_wands: the number of pixel wands returned (0 on failure).
%
*/
-WandExport PixelWand **PixelGetCurrentIteratorRow(PixelIterator *iterator,
+static PixelWand **ReadIteratorRow(PixelIterator *iterator,
size_t *number_wands)
{
+ const Image
+ *image;
+
const Quantum
*pixels;
ssize_t
x;
- assert(iterator != (PixelIterator *) NULL);
- assert(iterator->signature == MagickWandSignature);
- if (iterator->debug != MagickFalse)
- (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
*number_wands=0;
- iterator->active=MagickTrue;
pixels=GetCacheViewVirtualPixels(iterator->view,iterator->region.x,
iterator->region.y+iterator->y,iterator->region.width,1,
iterator->exception);
if (pixels == (const Quantum *) NULL)
return((PixelWand **) NULL);
+ image=GetCacheViewImage(iterator->view);
for (x=0; x < (ssize_t) iterator->region.width; x++)
{
- PixelSetQuantumPixel(GetCacheViewImage(iterator->view),pixels,
- iterator->pixel_wands[x]);
- pixels+=(ptrdiff_t) GetPixelChannels(GetCacheViewImage(iterator->view));
+ PixelSetQuantumPixel(image,pixels,iterator->pixel_wands[x]);
+ pixels+=(ptrdiff_t) GetPixelChannels(image);
}
*number_wands=iterator->region.width;
return(iterator->pixel_wands);
@@ -492,6 +496,43 @@ WandExport PixelWand **PixelGetCurrentIteratorRow(PixelIterator *iterator,
% %
% %
% %
+% P i x e l G e t C u r r e n t I t e r a t o r R o w %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% PixelGetCurrentIteratorRow() returns the current row as an array of pixel
+% wands from the pixel iterator.
+%
+% The format of the PixelGetCurrentIteratorRow method is:
+%
+% PixelWand **PixelGetCurrentIteratorRow(PixelIterator *iterator,
+% size_t *number_wands)
+%
+% A description of each parameter follows:
+%
+% o iterator: the pixel iterator.
+%
+% o number_wands: the number of pixel wands.
+%
+*/
+WandExport PixelWand **PixelGetCurrentIteratorRow(PixelIterator *iterator,
+ size_t *number_wands)
+{
+ assert(iterator != (PixelIterator *) NULL);
+ assert(iterator->signature == MagickWandSignature);
+ if (iterator->debug != MagickFalse)
+ (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
+ iterator->active=MagickTrue;
+ return(ReadIteratorRow(iterator,number_wands));
+}
+
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
% P i x e l G e t I t e r a t o r E x c e p t i o n %
% %
% %
@@ -537,11 +578,11 @@ WandExport char *PixelGetIteratorException(const PixelIterator *iterator,
MagickPathExtent);
if (iterator->exception->description != (char *) NULL)
{
- (void) ConcatenateMagickString(description," (",MagickPathExtent);
+ (void) ConcatenateMagickString(description," (",2UL*MagickPathExtent);
(void) ConcatenateMagickString(description,GetLocaleExceptionMessage(
iterator->exception->severity,iterator->exception->description),
- MagickPathExtent);
- (void) ConcatenateMagickString(description,")",MagickPathExtent);
+ 2UL*MagickPathExtent);
+ (void) ConcatenateMagickString(description,")",2UL*MagickPathExtent);
}
return(description);
}
@@ -640,12 +681,6 @@ WandExport ssize_t PixelGetIteratorRow(PixelIterator *iterator)
WandExport PixelWand **PixelGetNextIteratorRow(PixelIterator *iterator,
size_t *number_wands)
{
- const Quantum
- *pixels;
-
- ssize_t
- x;
-
assert(iterator != (PixelIterator *) NULL);
assert(iterator->signature == MagickWandSignature);
if (iterator->debug != MagickFalse)
@@ -655,19 +690,7 @@ WandExport PixelWand **PixelGetNextIteratorRow(PixelIterator *iterator,
iterator->y++;
if (PixelSetIteratorRow(iterator,iterator->y) == MagickFalse)
return((PixelWand **) NULL);
- pixels=GetCacheViewVirtualPixels(iterator->view,iterator->region.x,
- iterator->region.y+iterator->y,iterator->region.width,1,
- iterator->exception);
- if (pixels == (const Quantum *) NULL)
- return((PixelWand **) NULL);
- for (x=0; x < (ssize_t) iterator->region.width; x++)
- {
- PixelSetQuantumPixel(GetCacheViewImage(iterator->view),pixels,
- iterator->pixel_wands[x]);
- pixels+=(ptrdiff_t) GetPixelChannels(GetCacheViewImage(iterator->view));
- }
- *number_wands=iterator->region.width;
- return(iterator->pixel_wands);
+ return(ReadIteratorRow(iterator,number_wands));
}
/*
@@ -699,12 +722,6 @@ WandExport PixelWand **PixelGetNextIteratorRow(PixelIterator *iterator,
WandExport PixelWand **PixelGetPreviousIteratorRow(PixelIterator *iterator,
size_t *number_wands)
{
- const Quantum
- *pixels;
-
- ssize_t
- x;
-
assert(iterator != (PixelIterator *) NULL);
assert(iterator->signature == MagickWandSignature);
if (iterator->debug != MagickFalse)
@@ -714,19 +731,7 @@ WandExport PixelWand **PixelGetPreviousIteratorRow(PixelIterator *iterator,
iterator->y--;
if (PixelSetIteratorRow(iterator,iterator->y) == MagickFalse)
return((PixelWand **) NULL);
- pixels=GetCacheViewVirtualPixels(iterator->view,iterator->region.x,
- iterator->region.y+iterator->y,iterator->region.width,1,
- iterator->exception);
- if (pixels == (const Quantum *) NULL)
- return((PixelWand **) NULL);
- for (x=0; x < (ssize_t) iterator->region.width; x++)
- {
- PixelSetQuantumPixel(GetCacheViewImage(iterator->view),pixels,
- iterator->pixel_wands[x]);
- pixels+=(ptrdiff_t) GetPixelChannels(GetCacheViewImage(iterator->view));
- }
- *number_wands=iterator->region.width;
- return(iterator->pixel_wands);
+ return(ReadIteratorRow(iterator,number_wands));
}
/*
@@ -792,7 +797,7 @@ WandExport void PixelSetFirstIteratorRow(PixelIterator *iterator)
if (iterator->debug != MagickFalse)
(void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
iterator->active=MagickFalse;
- iterator->y=iterator->region.y;
+ iterator->y=0;
}
/*
@@ -916,7 +921,8 @@ WandExport MagickBooleanType PixelSyncIterator(PixelIterator *iterator)
iterator->pixel_wands[x],pixels);
pixels+=(ptrdiff_t) GetPixelChannels(GetCacheViewImage(iterator->view));
}
- if (SyncCacheViewAuthenticPixels(iterator->view,iterator->exception) == MagickFalse)
+ if (SyncCacheViewAuthenticPixels(iterator->view,iterator->exception) ==
+ MagickFalse)
return(MagickFalse);
return(MagickTrue);
}