mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
Fix various memory leaks
Bugfixes thanks to Alex Haley <ahaley42@users.sf.net>
This commit is contained in:
parent
e6ff154543
commit
a7bcef4ef7
@ -236,5 +236,6 @@ int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
|
|||||||
fwrite(bitmap_file_start, file_header.file_size, 1, bmp_file);
|
fwrite(bitmap_file_start, file_header.file_size, 1, bmp_file);
|
||||||
fclose(bmp_file);
|
fclose(bmp_file);
|
||||||
|
|
||||||
|
free(bitmap_file_start);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -497,6 +497,7 @@ int gif_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
|
|||||||
image_height * image_width);
|
image_height * image_width);
|
||||||
if (byte_out <= 0)
|
if (byte_out <= 0)
|
||||||
{
|
{
|
||||||
|
fclose(gif_file);
|
||||||
return ZINT_ERROR_MEMORY;
|
return ZINT_ERROR_MEMORY;
|
||||||
}
|
}
|
||||||
fwrite(lzwoutbuf, byte_out, 1, gif_file);
|
fwrite(lzwoutbuf, byte_out, 1, gif_file);
|
||||||
|
@ -105,6 +105,8 @@ void ZBarcode_Delete(struct zint_symbol *symbol) {
|
|||||||
if (symbol->rendered != NULL) {
|
if (symbol->rendered != NULL) {
|
||||||
struct zint_render_line *line, *l;
|
struct zint_render_line *line, *l;
|
||||||
struct zint_render_string *string, *s;
|
struct zint_render_string *string, *s;
|
||||||
|
struct zint_render_ring *ring, *r;
|
||||||
|
struct zint_render_hexagon *hexagon, *h;
|
||||||
|
|
||||||
// Free lines
|
// Free lines
|
||||||
line = symbol->rendered->lines;
|
line = symbol->rendered->lines;
|
||||||
@ -122,6 +124,22 @@ void ZBarcode_Delete(struct zint_symbol *symbol) {
|
|||||||
free(s);
|
free(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Free Rings
|
||||||
|
ring = symbol->rendered->rings;
|
||||||
|
while (ring) {
|
||||||
|
r = ring;
|
||||||
|
ring = ring->next;
|
||||||
|
free(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Free Hexagons
|
||||||
|
hexagon = symbol->rendered->hexagons;
|
||||||
|
while (hexagon) {
|
||||||
|
h = hexagon;
|
||||||
|
hexagon = hexagon->next;
|
||||||
|
free(h);
|
||||||
|
}
|
||||||
|
|
||||||
// Free Render
|
// Free Render
|
||||||
free(symbol->rendered);
|
free(symbol->rendered);
|
||||||
}
|
}
|
||||||
|
@ -115,20 +115,24 @@ int ps_plot(struct zint_symbol *symbol) {
|
|||||||
|
|
||||||
if (strlen(symbol->fgcolour) != 6) {
|
if (strlen(symbol->fgcolour) != 6) {
|
||||||
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
||||||
|
fclose(feps);
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
}
|
}
|
||||||
if (strlen(symbol->bgcolour) != 6) {
|
if (strlen(symbol->bgcolour) != 6) {
|
||||||
strcpy(symbol->errtxt, "Malformed background colour target");
|
strcpy(symbol->errtxt, "Malformed background colour target");
|
||||||
|
fclose(feps);
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
}
|
}
|
||||||
error_number = is_sane(SSET, (unsigned char*) symbol->fgcolour, strlen(symbol->fgcolour));
|
error_number = is_sane(SSET, (unsigned char*) symbol->fgcolour, strlen(symbol->fgcolour));
|
||||||
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||||
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
||||||
|
fclose(feps);
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
}
|
}
|
||||||
error_number = is_sane(SSET, (unsigned char*) symbol->bgcolour, strlen(symbol->bgcolour));
|
error_number = is_sane(SSET, (unsigned char*) symbol->bgcolour, strlen(symbol->bgcolour));
|
||||||
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||||
strcpy(symbol->errtxt, "Malformed background colour target");
|
strcpy(symbol->errtxt, "Malformed background colour target");
|
||||||
|
fclose(feps);
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
}
|
}
|
||||||
locale = setlocale(LC_ALL, "C");
|
locale = setlocale(LC_ALL, "C");
|
||||||
|
@ -341,6 +341,7 @@ int plot_raster_maxicode(struct zint_symbol *symbol, int rotate_angle, int data_
|
|||||||
/* Apply scale options by creating another pixel buffer */
|
/* Apply scale options by creating another pixel buffer */
|
||||||
if (!(scaled_pixelbuf = (char *) malloc(scale_width * scale_height))) {
|
if (!(scaled_pixelbuf = (char *) malloc(scale_width * scale_height))) {
|
||||||
printf("Insufficient memory for pixel buffer");
|
printf("Insufficient memory for pixel buffer");
|
||||||
|
free(pixelbuf);
|
||||||
return ZINT_ERROR_ENCODING_PROBLEM;
|
return ZINT_ERROR_ENCODING_PROBLEM;
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < (scale_width * scale_height); i++) {
|
for (i = 0; i < (scale_width * scale_height); i++) {
|
||||||
@ -902,6 +903,7 @@ int plot_raster_default(struct zint_symbol *symbol, int rotate_angle, int data_t
|
|||||||
|
|
||||||
/* Apply scale options by creating another pixel buffer */
|
/* Apply scale options by creating another pixel buffer */
|
||||||
if (!(scaled_pixelbuf = (char *) malloc(scale_width * scale_height))) {
|
if (!(scaled_pixelbuf = (char *) malloc(scale_width * scale_height))) {
|
||||||
|
free(pixelbuf);
|
||||||
printf("Insufficient memory for pixel buffer");
|
printf("Insufficient memory for pixel buffer");
|
||||||
return ZINT_ERROR_ENCODING_PROBLEM;
|
return ZINT_ERROR_ENCODING_PROBLEM;
|
||||||
} else {
|
} else {
|
||||||
|
@ -111,20 +111,24 @@ int svg_plot(struct zint_symbol *symbol) {
|
|||||||
|
|
||||||
if (strlen(symbol->fgcolour) != 6) {
|
if (strlen(symbol->fgcolour) != 6) {
|
||||||
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
||||||
|
fclose(fsvg);
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
}
|
}
|
||||||
if (strlen(symbol->bgcolour) != 6) {
|
if (strlen(symbol->bgcolour) != 6) {
|
||||||
strcpy(symbol->errtxt, "Malformed background colour target");
|
strcpy(symbol->errtxt, "Malformed background colour target");
|
||||||
|
fclose(fsvg);
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
}
|
}
|
||||||
error_number = is_sane(SSET, (unsigned char*) symbol->fgcolour, strlen(symbol->fgcolour));
|
error_number = is_sane(SSET, (unsigned char*) symbol->fgcolour, strlen(symbol->fgcolour));
|
||||||
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||||
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
||||||
|
fclose(fsvg);
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
}
|
}
|
||||||
error_number = is_sane(SSET, (unsigned char*) symbol->bgcolour, strlen(symbol->bgcolour));
|
error_number = is_sane(SSET, (unsigned char*) symbol->bgcolour, strlen(symbol->bgcolour));
|
||||||
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||||
strcpy(symbol->errtxt, "Malformed background colour target");
|
strcpy(symbol->errtxt, "Malformed background colour target");
|
||||||
|
fclose(fsvg);
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
}
|
}
|
||||||
locale = setlocale(LC_ALL, "C");
|
locale = setlocale(LC_ALL, "C");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user