mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
Fix memory leak in PostScript
Also match ZBarcode_Encode prototype with definition Fixes thanks to Alex Haley <ahaley42@sf>, Ref ticket #33
This commit is contained in:
parent
343b3b873e
commit
b49f3f0255
@ -786,17 +786,17 @@ static int reduced_charset(struct zint_symbol *symbol, const unsigned char *sour
|
||||
return error_number;
|
||||
}
|
||||
|
||||
int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int in_length) {
|
||||
int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int length) {
|
||||
int error_number, error_buffer, i;
|
||||
#ifdef _MSC_VER
|
||||
unsigned char* local_source;
|
||||
#endif
|
||||
error_number = 0;
|
||||
|
||||
if (in_length == 0) {
|
||||
in_length = (int) ustrlen(source);
|
||||
if (length == 0) {
|
||||
length = (int) ustrlen(source);
|
||||
}
|
||||
if (in_length == 0) {
|
||||
if (length == 0) {
|
||||
strcpy(symbol->errtxt, "No input data");
|
||||
error_tag(symbol->errtxt, ZINT_ERROR_INVALID_DATA);
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
@ -810,9 +810,9 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int in_le
|
||||
#endif
|
||||
}
|
||||
#ifndef _MSC_VER
|
||||
unsigned char local_source[in_length + 1];
|
||||
unsigned char local_source[length + 1];
|
||||
#else
|
||||
local_source = (unsigned char*) _alloca(in_length + 1);
|
||||
local_source = (unsigned char*) _alloca(length + 1);
|
||||
#endif
|
||||
|
||||
/* First check the symbology field */
|
||||
@ -965,25 +965,25 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int in_le
|
||||
}
|
||||
|
||||
if (symbol->input_mode == GS1_MODE) {
|
||||
for (i = 0; i < in_length; i++) {
|
||||
for (i = 0; i < length; i++) {
|
||||
if (source[i] == '\0') {
|
||||
strcpy(symbol->errtxt, "NULL characters not permitted in GS1 mode");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
}
|
||||
if (gs1_compliant(symbol->symbology) == 1) {
|
||||
error_number = ugs1_verify(symbol, source, in_length, local_source);
|
||||
error_number = ugs1_verify(symbol, source, length, local_source);
|
||||
if (error_number != 0) {
|
||||
return error_number;
|
||||
}
|
||||
in_length = ustrlen(local_source);
|
||||
length = ustrlen(local_source);
|
||||
} else {
|
||||
strcpy(symbol->errtxt, "Selected symbology does not support GS1 mode");
|
||||
return ZINT_ERROR_INVALID_OPTION;
|
||||
}
|
||||
} else {
|
||||
memcpy(local_source, source, in_length);
|
||||
local_source[in_length] = '\0';
|
||||
memcpy(local_source, source, length);
|
||||
local_source[length] = '\0';
|
||||
}
|
||||
|
||||
switch (symbol->symbology) {
|
||||
@ -991,17 +991,17 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int in_le
|
||||
case BARCODE_MICROQR:
|
||||
case BARCODE_GRIDMATRIX:
|
||||
case BARCODE_HANXIN:
|
||||
error_number = extended_charset(symbol, local_source, in_length);
|
||||
error_number = extended_charset(symbol, local_source, length);
|
||||
break;
|
||||
default:
|
||||
error_number = reduced_charset(symbol, local_source, in_length);
|
||||
error_number = reduced_charset(symbol, local_source, length);
|
||||
break;
|
||||
}
|
||||
|
||||
if ((error_number == ZINT_ERROR_INVALID_DATA) && (supports_eci(symbol->symbology)
|
||||
&& (symbol->input_mode == UNICODE_MODE))) {
|
||||
/* Try another ECI mode */
|
||||
symbol->eci = get_best_eci(local_source, in_length);
|
||||
symbol->eci = get_best_eci(local_source, length);
|
||||
|
||||
if (symbol->eci >= 3) {
|
||||
|
||||
@ -1012,18 +1012,18 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int in_le
|
||||
case BARCODE_MICROQR:
|
||||
case BARCODE_GRIDMATRIX:
|
||||
case BARCODE_HANXIN:
|
||||
error_number = utf_to_eci(symbol->eci, source, local_source, &in_length);
|
||||
error_number = extended_charset(symbol, local_source, in_length);
|
||||
error_number = utf_to_eci(symbol->eci, source, local_source, &length);
|
||||
error_number = extended_charset(symbol, local_source, length);
|
||||
break;
|
||||
default:
|
||||
error_number = reduced_charset(symbol, local_source, in_length);
|
||||
error_number = reduced_charset(symbol, local_source, length);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((symbol->symbology == BARCODE_CODE128) || (symbol->symbology == BARCODE_CODE128B)) {
|
||||
for (i = 0; i < in_length; i++) {
|
||||
for (i = 0; i < length; i++) {
|
||||
if (local_source[i] == '\0') {
|
||||
symbol->text[i] = ' ';
|
||||
} else {
|
||||
|
19
backend/ps.c
19
backend/ps.c
@ -106,6 +106,9 @@ int ps_plot(struct zint_symbol *symbol) {
|
||||
}
|
||||
if (feps == NULL) {
|
||||
strcpy(symbol->errtxt, "Could not open output file");
|
||||
#ifdef _MSC_VER
|
||||
free(local_text);
|
||||
#endif
|
||||
return ZINT_ERROR_FILE_ACCESS;
|
||||
}
|
||||
|
||||
@ -116,23 +119,35 @@ int ps_plot(struct zint_symbol *symbol) {
|
||||
if (strlen(symbol->fgcolour) != 6) {
|
||||
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
||||
fclose(feps);
|
||||
#ifdef _MSC_VER
|
||||
free(local_text);
|
||||
#endif
|
||||
return ZINT_ERROR_INVALID_OPTION;
|
||||
}
|
||||
if (strlen(symbol->bgcolour) != 6) {
|
||||
strcpy(symbol->errtxt, "Malformed background colour target");
|
||||
fclose(feps);
|
||||
#ifdef _MSC_VER
|
||||
free(local_text);
|
||||
#endif
|
||||
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);
|
||||
#ifdef _MSC_VER
|
||||
free(local_text);
|
||||
#endif
|
||||
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);
|
||||
#ifdef _MSC_VER
|
||||
free(local_text);
|
||||
#endif
|
||||
return ZINT_ERROR_INVALID_OPTION;
|
||||
}
|
||||
locale = setlocale(LC_ALL, "C");
|
||||
@ -951,5 +966,9 @@ int ps_plot(struct zint_symbol *symbol) {
|
||||
if (locale)
|
||||
setlocale(LC_ALL, locale);
|
||||
|
||||
#ifdef _MSC_VER
|
||||
free(local_text);
|
||||
#endif
|
||||
|
||||
return error_number;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user