Fix memory leak problem in fromsixel.c
@@ -969,31 +969,33 @@ sixel_decode_raw(
image_buffer_t image;
int n;
+ image.data = NULL;
+
if (allocator) {
sixel_allocator_ref(allocator);
} else {
status = sixel_allocator_new(&allocator, NULL, NULL, NULL, NULL);
if (SIXEL_FAILED(status)) {
allocator = NULL;
- goto end;
+ goto error;
}
}
/* parser context initialization */
status = parser_context_init(&context);
if (SIXEL_FAILED(status)) {
- goto end;
+ goto error;
}
/* buffer initialization */
status = image_buffer_init(&image, 1, 1, context.bgindex, allocator);
if (SIXEL_FAILED(status)) {
- goto end;
+ goto error;
}
status = sixel_decode_raw_impl(p, len, &image, &context, allocator);
if (SIXEL_FAILED(status)) {
- goto end;
+ goto error;
}
*ncolors = image.ncolors + 1;
@@ -1008,7 +1010,7 @@ sixel_decode_raw(
sixel_helper_set_additional_message(
"sixel_deocde_raw: sixel_allocator_malloc() failed.");
status = SIXEL_BAD_ALLOCATION;
- goto end;
+ goto error;
}
for (n = 0; n < *ncolors; ++n) {
(*palette)[n * 3 + 0] = image.palette[n] >> 16 & 0xff;
@@ -1021,6 +1023,11 @@ sixel_decode_raw(
*pixels = image.data;
status = SIXEL_OK;
+ goto end;
+
+error:
+ free(image.data);
+ image.data = NULL;
end:
sixel_allocator_unref(allocator);
