remove some redundant code and fixed CID# 416023 with resource leak

This commit is contained in:
iceman1001 2023-07-17 11:21:29 +02:00
commit 24938e3ed5

View file

@ -301,7 +301,8 @@ static void init_bitflip_bitarrays(void) {
free(path); free(path);
if (statesfile == NULL) { if (statesfile == NULL) {
continue; continue;
} else if (open_uncompressed) { }
fseek(statesfile, 0, SEEK_END); fseek(statesfile, 0, SEEK_END);
int fsize = ftell(statesfile); int fsize = ftell(statesfile);
if (fsize == -1) { if (fsize == -1) {
@ -312,6 +313,8 @@ static void init_bitflip_bitarrays(void) {
uint32_t filesize = (uint32_t)fsize; uint32_t filesize = (uint32_t)fsize;
rewind(statesfile); rewind(statesfile);
if (open_uncompressed) {
uint32_t count = 0; uint32_t count = 0;
size_t bytesread = fread(&count, 1, sizeof(count), statesfile); size_t bytesread = fread(&count, 1, sizeof(count), statesfile);
if (bytesread != 4) { if (bytesread != 4) {
@ -347,18 +350,12 @@ static void init_bitflip_bitarrays(void) {
} }
#endif #endif
} }
fclose(statesfile);
nraw++; nraw++;
continue;
} else if (open_lz4compressed) { } else if (open_lz4compressed) {
fseek(statesfile, 0, SEEK_END);
int fsize = ftell(statesfile);
if (fsize == -1) {
PrintAndLogEx(ERR, "File read error with %s (1). Aborting...\n", state_file_name);
fclose(statesfile);
exit(5);
}
uint32_t filesize = (uint32_t)fsize;
rewind(statesfile);
char *compressed_data = calloc(filesize, sizeof(uint8_t)); char *compressed_data = calloc(filesize, sizeof(uint8_t));
if (compressed_data == NULL) { if (compressed_data == NULL) {
PrintAndLogEx(ERR, "Out of memory error in init_bitflip_statelists(). Aborting...\n"); PrintAndLogEx(ERR, "Out of memory error in init_bitflip_statelists(). Aborting...\n");
@ -436,15 +433,6 @@ static void init_bitflip_bitarrays(void) {
continue; continue;
} else if (open_bz2compressed) { } else if (open_bz2compressed) {
fseek(statesfile, 0, SEEK_END);
int fsize = ftell(statesfile);
if (fsize == -1) {
PrintAndLogEx(ERR, "File read error with %s. Aborting...\n", state_file_name);
fclose(statesfile);
exit(5);
}
uint32_t filesize = (uint32_t)fsize;
rewind(statesfile);
char input_buffer[filesize]; char input_buffer[filesize];
size_t bytesread = fread(input_buffer, 1, filesize, statesfile); size_t bytesread = fread(input_buffer, 1, filesize, statesfile);
if (bytesread != filesize) { if (bytesread != filesize) {