Fix various memory leaks

Bugfixes thanks to Alex Haley <ahaley42@users.sf.net>
This commit is contained in:
Robin Stuart 2016-09-03 18:45:09 +01:00
parent e6ff154543
commit a7bcef4ef7
6 changed files with 400 additions and 370 deletions

View File

@ -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);
fclose(bmp_file);
free(bitmap_file_start);
return 0;
}

View File

@ -497,6 +497,7 @@ int gif_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
image_height * image_width);
if (byte_out <= 0)
{
fclose(gif_file);
return ZINT_ERROR_MEMORY;
}
fwrite(lzwoutbuf, byte_out, 1, gif_file);

View File

@ -105,6 +105,8 @@ void ZBarcode_Delete(struct zint_symbol *symbol) {
if (symbol->rendered != NULL) {
struct zint_render_line *line, *l;
struct zint_render_string *string, *s;
struct zint_render_ring *ring, *r;
struct zint_render_hexagon *hexagon, *h;
// Free lines
line = symbol->rendered->lines;
@ -122,6 +124,22 @@ void ZBarcode_Delete(struct zint_symbol *symbol) {
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(symbol->rendered);
}

View File

@ -115,20 +115,24 @@ int ps_plot(struct zint_symbol *symbol) {
if (strlen(symbol->fgcolour) != 6) {
strcpy(symbol->errtxt, "Malformed foreground colour target");
fclose(feps);
return ZINT_ERROR_INVALID_OPTION;
}
if (strlen(symbol->bgcolour) != 6) {
strcpy(symbol->errtxt, "Malformed background colour target");
fclose(feps);
return ZINT_ERROR_INVALID_OPTION;
}
error_number = is_sane(SSET, (unsigned char*) symbol->fgcolour, strlen(symbol->fgcolour));
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "Malformed foreground colour target");
fclose(feps);
return ZINT_ERROR_INVALID_OPTION;
}
error_number = is_sane(SSET, (unsigned char*) symbol->bgcolour, strlen(symbol->bgcolour));
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "Malformed background colour target");
fclose(feps);
return ZINT_ERROR_INVALID_OPTION;
}
locale = setlocale(LC_ALL, "C");

View File

@ -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 */
if (!(scaled_pixelbuf = (char *) malloc(scale_width * scale_height))) {
printf("Insufficient memory for pixel buffer");
free(pixelbuf);
return ZINT_ERROR_ENCODING_PROBLEM;
} else {
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 */
if (!(scaled_pixelbuf = (char *) malloc(scale_width * scale_height))) {
free(pixelbuf);
printf("Insufficient memory for pixel buffer");
return ZINT_ERROR_ENCODING_PROBLEM;
} else {

View File

@ -111,20 +111,24 @@ int svg_plot(struct zint_symbol *symbol) {
if (strlen(symbol->fgcolour) != 6) {
strcpy(symbol->errtxt, "Malformed foreground colour target");
fclose(fsvg);
return ZINT_ERROR_INVALID_OPTION;
}
if (strlen(symbol->bgcolour) != 6) {
strcpy(symbol->errtxt, "Malformed background colour target");
fclose(fsvg);
return ZINT_ERROR_INVALID_OPTION;
}
error_number = is_sane(SSET, (unsigned char*) symbol->fgcolour, strlen(symbol->fgcolour));
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "Malformed foreground colour target");
fclose(fsvg);
return ZINT_ERROR_INVALID_OPTION;
}
error_number = is_sane(SSET, (unsigned char*) symbol->bgcolour, strlen(symbol->bgcolour));
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "Malformed background colour target");
fclose(fsvg);
return ZINT_ERROR_INVALID_OPTION;
}
locale = setlocale(LC_ALL, "C");