Commit d4882419 authored by Ulrich Sibiller's avatar Ulrich Sibiller Committed by Mike Gabriel

compext/Png.c: late image_index allocation

Move allocation of image_index close before first_use. This way we do not need to free it if previous step fail. And we cannot forget that free() call. While at it replace malloc+memset by calloc.
parent b4d3dc5b
......@@ -253,17 +253,6 @@ char *PngCompressData(XImage *image, int *compressed_size)
NXColorTable color_table[NB_COLOR_MAX];
CARD8 *image_index;
image_index = (CARD8 *) malloc((image -> height) * (image -> width) * sizeof(CARD8));
/*
* TODO: Be sure the padded bytes are cleaned.
* It would be better to set to zero the bytes
* that are not aligned to the word boundary
* at the end of the procedure.
*/
memset(image_index, 0, (image -> height) * (image -> width) * sizeof(CARD8));
*compressed_size = 0;
pngDataLen = 0;
......@@ -283,7 +272,6 @@ char *PngCompressData(XImage *image, int *compressed_size)
bitsPerPixel);
#endif
free(image_index);
return NULL;
}
......@@ -316,7 +304,6 @@ char *PngCompressData(XImage *image, int *compressed_size)
fprintf(stderr, "******PngCompressData: PANIC! Failed creating the png_create_write_struct.\n");
#endif
free(image_index);
return NULL;
}
......@@ -329,7 +316,6 @@ char *PngCompressData(XImage *image, int *compressed_size)
#endif
png_destroy_write_struct(&png_ptr, NULL);
free(image_index);
return NULL;
}
......@@ -341,7 +327,6 @@ char *PngCompressData(XImage *image, int *compressed_size)
#endif
png_destroy_write_struct(&png_ptr, &info_ptr);
free(image_index);
return NULL;
}
......@@ -364,8 +349,6 @@ char *PngCompressData(XImage *image, int *compressed_size)
PNG_DEST_SIZE(w, h));
#endif
free(image_index);
return NULL;
}
......@@ -383,6 +366,24 @@ char *PngCompressData(XImage *image, int *compressed_size)
return NULL;
}
image_index = (CARD8 *) calloc(1, (image -> height) * (image -> width) * sizeof(CARD8));
if (image_index == NULL)
{
#ifdef PANIC
fprintf(stderr, "******PngCompressData: PANIC! Could not alloc image_index.\n");
#endif
free(pngCompBuf);
return NULL;
}
/*
* TODO: Be sure the padded bytes are cleaned.
* It would be better to set to zero the bytes
* that are not aligned to the word boundary
* at the end of the procedure.
*/
png_set_compression_level(png_ptr, PNG_Z_LEVEL);
if (bitsPerPixel == 16)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment