Skip to content

Commit

Permalink
Fixed memory leak reported in #428.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed Apr 17, 2017
1 parent fd84a5e commit 721dc13
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions coders/sgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,10 @@ static Image *ReadSGIImage(const ImageInfo *image_info,ExceptionInfo *exception)
scanline=(unsigned char *) AcquireQuantumMemory(iris_info.columns,
bytes_per_pixel*sizeof(*scanline));
if (scanline == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
{
pixel_info=RelinquishVirtualMemory(pixel_info);
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
}
for (z=0; z < (ssize_t) iris_info.depth; z++)
{
p=pixels+bytes_per_pixel*z;
Expand Down Expand Up @@ -460,12 +463,11 @@ static Image *ReadSGIImage(const ImageInfo *image_info,ExceptionInfo *exception)
(runlength == (size_t *) NULL) ||
(packet_info == (MemoryInfo *) NULL))
{
if (offsets == (ssize_t *) NULL)
offsets=(ssize_t *) RelinquishMagickMemory(offsets);
if (runlength == (size_t *) NULL)
runlength=(size_t *) RelinquishMagickMemory(runlength);
if (packet_info == (MemoryInfo *) NULL)
offsets=(ssize_t *) RelinquishMagickMemory(offsets);
runlength=(size_t *) RelinquishMagickMemory(runlength);
if (packet_info != (MemoryInfo *) NULL)
packet_info=RelinquishVirtualMemory(packet_info);
pixel_info=RelinquishVirtualMemory(pixel_info);
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
}
packets=(unsigned char *) GetVirtualMemoryBlob(packet_info);
Expand All @@ -475,7 +477,13 @@ static Image *ReadSGIImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
runlength[i]=ReadBlobMSBLong(image);
if (runlength[i] > (4*(size_t) iris_info.columns+10))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
{
offsets=(ssize_t *) RelinquishMagickMemory(offsets);
runlength=(size_t *) RelinquishMagickMemory(runlength);
packet_info=RelinquishVirtualMemory(packet_info);
pixel_info=RelinquishVirtualMemory(pixel_info);
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
}
}
/*
Check data order.
Expand Down Expand Up @@ -512,7 +520,14 @@ static Image *ReadSGIImage(const ImageInfo *image_info,ExceptionInfo *exception)
(runlength[y+z*iris_info.rows]/bytes_per_pixel),packets,
(ssize_t) iris_info.columns,p+bytes_per_pixel*z);
if (status == MagickFalse)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
{
offsets=(ssize_t *) RelinquishMagickMemory(offsets);
runlength=(size_t *) RelinquishMagickMemory(runlength);
packet_info=RelinquishVirtualMemory(packet_info);
pixel_info=RelinquishVirtualMemory(pixel_info);
ThrowReaderException(CorruptImageError,
"ImproperImageHeader");
}
p+=(iris_info.columns*4*bytes_per_pixel);
}
}
Expand Down Expand Up @@ -543,7 +558,14 @@ static Image *ReadSGIImage(const ImageInfo *image_info,ExceptionInfo *exception)
(runlength[y+z*iris_info.rows]/bytes_per_pixel),packets,
(ssize_t) iris_info.columns,p+bytes_per_pixel*z);
if (status == MagickFalse)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
{
offsets=(ssize_t *) RelinquishMagickMemory(offsets);
runlength=(size_t *) RelinquishMagickMemory(runlength);
packet_info=RelinquishVirtualMemory(packet_info);
pixel_info=RelinquishVirtualMemory(pixel_info);
ThrowReaderException(CorruptImageError,
"ImproperImageHeader");
}
}
p+=(iris_info.columns*4*bytes_per_pixel);
}
Expand Down

0 comments on commit 721dc13

Please sign in to comment.