[X2Go-Commits] [nx-libs] 102/219: compext/Png.c: late image_index allocation
git-admin at x2go.org
git-admin at x2go.org
Sat Sep 28 12:10:31 CEST 2019
This is an automated email from the git hooks/post-receive script.
x2go pushed a commit to branch 3.6.x
in repository nx-libs.
commit d48824195009b2497b4233c9d3f2a8f9c1e6a2d7
Author: Ulrich Sibiller <uli42 at gmx.de>
Date: Thu Jun 20 19:51:00 2019 +0200
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.
---
nx-X11/programs/Xserver/hw/nxagent/compext/Png.c | 35 ++++++++++++------------
1 file 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)
--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/nx-libs.git
More information about the x2go-commits
mailing list