fix: mem leaks.
This commit is contained in:
@@ -538,18 +538,19 @@ int bruteforceFile(const char *filename, uint16_t keytable[]) {
|
||||
|
||||
if (fsize < 0) {
|
||||
PrintAndLogDevice(WARNING, "Error, when getting filesize");
|
||||
if (f) fclose(f);
|
||||
fclose(f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t *dump = calloc(fsize, sizeof(uint8_t));
|
||||
if ( !dump ) {
|
||||
PrintAndLogDevice(WARNING, "Failed to allocate memory");
|
||||
fclose(f);
|
||||
return 2;
|
||||
}
|
||||
size_t bytes_read = fread(dump, 1, fsize, f);
|
||||
|
||||
if (f) fclose(f);
|
||||
fclose(f);
|
||||
|
||||
if (bytes_read < fsize) {
|
||||
PrintAndLogDevice(WARNING, "Error, could only read %d bytes (should be %d)", bytes_read, fsize );
|
||||
|
||||
@@ -266,8 +266,8 @@ int loadFile(const char *preferredName, const char *suffix, void* data, size_t*
|
||||
FILE *f = fopen(fileName, "rb");
|
||||
if ( !f ) {
|
||||
PrintAndLogDevice(WARNING, "file not found or locked. '" _YELLOW_(%s)"'", fileName);
|
||||
retval = 1;
|
||||
goto out;
|
||||
free(fileName);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// get filesize in order to malloc memory
|
||||
@@ -310,7 +310,12 @@ int loadFile(const char *preferredName, const char *suffix, void* data, size_t*
|
||||
|
||||
out:
|
||||
fclose(f);
|
||||
|
||||
if (data)
|
||||
free(data);
|
||||
|
||||
free(fileName);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
@@ -685,7 +685,7 @@ static bool readKeyFile(uint8_t key[8]) {
|
||||
sprintf(filename, "%s.bin", "client/loclass/iclass_key");
|
||||
}
|
||||
|
||||
if ( filename == NULL )
|
||||
if ( strlen(filename) == 0 )
|
||||
return retval;
|
||||
|
||||
FILE *f = fopen(filename, "rb");
|
||||
|
||||
Reference in New Issue
Block a user