fix, resource leaks

This commit is contained in:
iceman1001 2020-06-07 19:33:32 +02:00
commit 9a2a5496c0

View file

@ -91,8 +91,10 @@ static int zlib_compress(FILE *infile[], uint8_t num_infiles, FILE *outfile, boo
} while (!all_feof(infile, num_infiles));
uint32_t buffer_size = FPGA_RING_BUFFER_BYTES;
if (num_infiles == 1)
buffer_size = 1024*1024; //1M for now
uint32_t outsize_max = LZ4_compressBound(buffer_size);
char *outbuf = calloc(outsize_max, sizeof(char));
@ -145,7 +147,7 @@ static int zlib_compress(FILE *infile[], uint8_t num_infiles, FILE *outfile, boo
typedef struct lz4_stream_s {
LZ4_streamDecode_t* lz4StreamDecode;
char * next_in;
char* next_in;
int avail_in;
} lz4_stream;
@ -158,10 +160,11 @@ static int zlib_decompress(FILE *infile, FILE *outfile) {
long infile_size = ftell(infile);
fseek(infile, 0L, SEEK_SET);
char * inbuf = calloc(infile_size, sizeof(char));
char* inbuf = calloc(infile_size, sizeof(char));
size_t num_read = fread(inbuf, sizeof(char), infile_size, infile);
if (num_read != infile_size) {
free(inbuf);
return (EXIT_FAILURE);
}
@ -188,6 +191,7 @@ static int zlib_decompress(FILE *infile, FILE *outfile) {
printf("uncompressed %li input bytes to %i output bytes\n", infile_size, total_size);
fclose(outfile);
fclose(infile);
free(inbuf);
return (EXIT_SUCCESS);
}
@ -280,7 +284,7 @@ static int FpgaGatherVersion(FILE *infile, char *infile_name, char *dst, int len
strncat(dst, " on ", len - strlen(dst) - 1);
for (uint16_t i = 0; i < fpga_info_len; i++) {
char c = (char)fgetc(infile);
if (i < sizeof(tempstr)) {
if (i < sizeof(tempstr)) {
if (c == '/') c = '-';
if (c == ' ') c = '0';
tempstr[i] = c;
@ -314,8 +318,8 @@ static void print_version_info_preamble(FILE *outfile, int num_infiles) {
fprintf(outfile, "//\n");
fprintf(outfile, "// This file is generated by fpga_compress. Don't edit!\n");
fprintf(outfile, "//-----------------------------------------------------------------------------\n");
fprintf(outfile, "\n");
fprintf(outfile, "\n");
fprintf(outfile, "// slurdge, 2020\n");
fprintf(outfile, "\n\n");
fprintf(outfile, "const int g_fpga_bitstream_num = %d;\n", num_infiles);
fprintf(outfile, "const char *const g_fpga_version_information[%d] = {\n", num_infiles);
}