summaryrefslogtreecommitdiffstats
path: root/apps/plugins/imageviewer/gif/gif_decoder.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/imageviewer/gif/gif_decoder.c')
-rw-r--r--apps/plugins/imageviewer/gif/gif_decoder.c43
1 files changed, 32 insertions, 11 deletions
diff --git a/apps/plugins/imageviewer/gif/gif_decoder.c b/apps/plugins/imageviewer/gif/gif_decoder.c
index 0fde184ec2..a1fda43a46 100644
--- a/apps/plugins/imageviewer/gif/gif_decoder.c
+++ b/apps/plugins/imageviewer/gif/gif_decoder.c
@@ -115,6 +115,11 @@ void gif_decoder_init(struct gif_decoder *d, void *mem, size_t size)
init_memory_pool(d->mem_size, d->mem);
}
+void gif_decoder_destroy_memory_pool(struct gif_decoder *d)
+{
+ destroy_memory_pool(d->mem);
+}
+
void gif_open(char *filename, struct gif_decoder *d)
{
if ((GifFile = DGifOpenFileName(filename, &d->error)) == NULL)
@@ -181,6 +186,7 @@ void gif_decode(struct gif_decoder *d,
{
/* error allocating temp space */
d->error = D_GIF_ERR_NOT_ENOUGH_MEM;
+ DGifCloseFile(GifFile);
return;
}
@@ -196,7 +202,7 @@ void gif_decode(struct gif_decoder *d,
if (pixels_buffer[0] == NULL)
{
d->error = D_GIF_ERR_NOT_ENOUGH_MEM;
- return;
+ goto free_and_return;
}
/* Global background color */
@@ -215,7 +221,7 @@ void gif_decode(struct gif_decoder *d,
if (DGifGetRecordType(GifFile, &RecordType) == GIF_ERROR)
{
d->error = GifFile->Error;
- return;
+ goto free_and_return;
}
switch (RecordType)
@@ -225,7 +231,7 @@ void gif_decode(struct gif_decoder *d,
if (DGifGetImageDesc(GifFile) == GIF_ERROR)
{
d->error = GifFile->Error;
- return;
+ goto free_and_return;
}
/* Image Position relative to canvas */
@@ -239,7 +245,7 @@ void gif_decode(struct gif_decoder *d,
GifFile->SColorMap == NULL)
{
d->error = D_GIF_ERR_NO_COLOR_MAP;
- return;
+ goto free_and_return;
}
/* sanity check */
@@ -247,7 +253,7 @@ void gif_decode(struct gif_decoder *d,
GifFile->Image.Top+GifFile->Image.Height>GifFile->SHeight)
{
d->error = D_GIF_ERR_DATA_TOO_BIG;
- return;
+ goto free_and_return;
}
if (GifFile->Image.GCB &&
@@ -275,7 +281,7 @@ void gif_decode(struct gif_decoder *d,
if (DGifGetLine(GifFile, Line, Width) == GIF_ERROR)
{
d->error = GifFile->Error;
- return;
+ goto free_and_return;
}
gif2pixels(Line, pixels_buffer[buf_idx],
@@ -294,7 +300,7 @@ void gif_decode(struct gif_decoder *d,
if (DGifGetLine(GifFile, Line, Width) == GIF_ERROR)
{
d->error = GifFile->Error;
- return;
+ goto free_and_return;
}
gif2pixels(Line, pixels_buffer[buf_idx],
@@ -310,7 +316,7 @@ void gif_decode(struct gif_decoder *d,
if (out == NULL)
{
d->error = D_GIF_ERR_NOT_ENOUGH_MEM;
- return;
+ goto free_and_return;
}
bm.data = out + d->native_img_size*d->frames_count;
@@ -350,7 +356,7 @@ void gif_decode(struct gif_decoder *d,
GIF_ERROR)
{
d->error = GifFile->Error;
- return;
+ goto free_and_return;
}
if (ExtCode == GRAPHICS_EXT_FUNC_CODE)
@@ -364,7 +370,7 @@ void gif_decode(struct gif_decoder *d,
GifFile->Image.GCB) == GIF_ERROR)
{
d->error = GifFile->Error;
- return;
+ goto free_and_return;
}
d->delay = GifFile->Image.GCB->DelayTime;
}
@@ -375,7 +381,7 @@ void gif_decode(struct gif_decoder *d,
if (DGifGetExtensionNext(GifFile, &Extension) == GIF_ERROR)
{
d->error = GifFile->Error;
- return;
+ goto free_and_return;
}
}
break;
@@ -391,6 +397,10 @@ void gif_decode(struct gif_decoder *d,
if (DGifCloseFile(GifFile) == GIF_ERROR)
{
d->error = GifFile->Error;
+ free(pixels_buffer[0]);
+ if (pixels_buffer[1])
+ free(pixels_buffer[1]);
+ free(Line);
return;
}
@@ -472,4 +482,15 @@ void gif_decode(struct gif_decoder *d,
}
}
#endif
+ return;
+
+free_and_return:
+ if (Line)
+ free(Line);
+ if (pixels_buffer[0])
+ free(pixels_buffer[0]);
+ if (pixels_buffer[1])
+ free(pixels_buffer[1]);
+ DGifCloseFile(GifFile);
+ return;
}