fix: mem leaks.

This commit is contained in:
iceman1001 2019-02-21 16:17:49 +01:00
commit 6d63b3fbed
9 changed files with 28 additions and 12 deletions

View file

@ -242,7 +242,7 @@ static void printSep() {
PrintAndLogEx(NORMAL, "------------------------------------------------------------------------------------");
}
uint16_t PrintFliteBlock(uint16_t tracepos, uint8_t *trace,uint16_t tracelen) {
uint16_t PrintFliteBlock(uint16_t tracepos, uint8_t *trace, uint16_t tracelen) {
if (tracepos+19 >= tracelen)
return tracelen;
@ -273,8 +273,8 @@ uint16_t PrintFliteBlock(uint16_t tracepos, uint8_t *trace,uint16_t tracelen) {
case 0x0c: PrintAndLogEx(NORMAL, "S_PAD12: %s",line);break;
case 0x0d: PrintAndLogEx(NORMAL, "S_PAD13: %s",line);break;
case 0x0E: {
uint32_t regA = trace[3] + (trace[4]>>8) + (trace[5]>>16) + (trace[6]>>24);
uint32_t regB = trace[7] + (trace[8]>>8) + (trace[9]>>16) + (trace[10]>>24);
uint32_t regA = trace[3] | trace[4] << 8 | trace[5] << 16 | trace[ 6] << 24;
uint32_t regB = trace[7] | trace[8] << 8 | trace[9] << 16 | trace[10] << 24;
line[0] = 0;
for (int j = 0; j < 8; j++)
snprintf(line+( j * 2),110, "%02x", trace[j+11]);

View file

@ -2163,7 +2163,7 @@ int CmdHFiClassLookUp(const char *Cmd) {
uint8_t CSN[8];
uint8_t EPURSE[8] = { 0,0,0,0,0,0,0,0 };
uint8_t MACS[8];
uint8_t MACS[8]= { 0,0,0,0,0,0,0,0 };
uint8_t CCNR[12];
uint8_t MAC_TAG[4] = { 0,0,0,0 };

View file

@ -1245,8 +1245,10 @@ int CmdHF14AMfNested(const char *Cmd) {
// Create dump file
if (createDumpFile) {
fptr = GenerateFilename("hf-mf-", "-key.bin");
if (fptr == NULL)
if (fptr == NULL) {
free(e_sector);
return 1;
}
if ((fkeys = fopen(fptr, "wb")) == NULL) {
PrintAndLogEx(WARNING, "could not create file " _YELLOW_(%s), fptr);
@ -1276,6 +1278,8 @@ int CmdHF14AMfNested(const char *Cmd) {
}
free(e_sector);
}
free(e_sector);
return 0;
}
@ -1971,7 +1975,8 @@ out:
if (createDumpFile) {
fptr = GenerateFilename("hf-mf-", "-key.bin");
if (fptr == NULL) {
free(keyBlock);
free(keyBlock);
free(e_sector);
return 1;
}

View file

@ -1982,6 +1982,7 @@ int CmdHF14AMfURestore(const char *Cmd){
uint8_t *dump = calloc(fsize, sizeof(uint8_t));
if ( !dump ) {
PrintAndLogEx(WARNING, "Failed to allocate memory");
fclose(f);
return 1;
}
@ -1990,6 +1991,7 @@ int CmdHF14AMfURestore(const char *Cmd){
fclose(f);
if ( bytes_read < 48 ) {
PrintAndLogEx(WARNING, "Error, dump file is too small");
free(dump);
return 1;
}

View file

@ -1022,8 +1022,10 @@ int CmdSmartBruteforceSFI(const char *Cmd) {
return 1;
PrintAndLogEx(INFO, "Selecting card");
if ( !smart_select(false, NULL) )
if ( !smart_select(false, NULL) ) {
free(buf);
return 1;
}
char* caid = NULL;

View file

@ -1807,6 +1807,7 @@ int CmdEMVRoca(const char *cmd) {
PrintAndLogEx(ERR, "Can't create PDOL data.");
tlvdb_free(tlvRoot);
DropFieldEx( channel );
free(pdol_data_tlv);
return 6;
}
PrintAndLogEx(INFO, "PDOL data[%d]: %s", pdol_data_tlv_data_len, sprint_hex(pdol_data_tlv_data, pdol_data_tlv_data_len));

View file

@ -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 );

View file

@ -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;
}

View file

@ -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");