diff options
author | Ulrich Sibiller <uli42@gmx.de> | 2019-06-20 19:51:00 +0200 |
---|---|---|
committer | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2019-06-22 11:30:47 +0200 |
commit | d48824195009b2497b4233c9d3f2a8f9c1e6a2d7 (patch) | |
tree | dc846e3272d074b039412944c1599bffddef51e5 /nx-X11 | |
parent | b4d3dc5bff6a8d3b09a61dbf8421a46fd23b82e8 (diff) | |
download | nx-libs-d48824195009b2497b4233c9d3f2a8f9c1e6a2d7.tar.gz nx-libs-d48824195009b2497b4233c9d3f2a8f9c1e6a2d7.tar.bz2 nx-libs-d48824195009b2497b4233c9d3f2a8f9c1e6a2d7.zip |
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.
Diffstat (limited to 'nx-X11')
-rw-r--r-- | nx-X11/programs/Xserver/hw/nxagent/compext/Png.c | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/nx-X11/programs/Xserver/hw/nxagent/compext/Png.c b/nx-X11/programs/Xserver/hw/nxagent/compext/Png.c index 0a258c5a3..e80f3879d 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/compext/Png.c +++ b/nx-X11/programs/Xserver/hw/nxagent/compext/Png.c @@ -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) |