fix few mem leaks

This commit is contained in:
Philippe Teuwen 2019-10-06 01:18:04 +02:00
parent 78c153fe74
commit 1f364106ce
14 changed files with 31 additions and 15 deletions

View file

@ -89,6 +89,8 @@ int GetModels(char *Models[], int *count, uint8_t *width) {
memcpy(tmp, model.name, size);
Models[mode] = tmp;
width[mode] = plen(model.spoly);
} else {
free(tmp);
}
}
mfree(&model);

View file

@ -757,6 +757,7 @@ static int CmdHFiClassELoad(const char *Cmd) {
}
default:
PrintAndLogEx(ERR, "No dictionary loaded");
free(dump);
return PM3_ESOFT;
}
@ -977,6 +978,7 @@ static int CmdHFiClassEncryptBlk(const char *Cmd) {
return PM3_EINVARG;
memcpy(key, keyptr, sizeof(key));
free(keyptr);
}
iClassEncryptBlkData(blk_data, key);

View file

@ -2607,7 +2607,10 @@ static int CmdHF14AMfChk(const char *Cmd) {
if (param_getchar(Cmd, 0) == '*') {
blockNo = 3;
SectorsCnt = NumOfSectors(param_getchar(Cmd + 1, 0));
if (SectorsCnt == 0) return usage_hf14_chk();
if (SectorsCnt == 0) {
free(keyBlock);
return usage_hf14_chk();
}
} else {
blockNo = param_get8(Cmd, 0);
}

View file

@ -142,7 +142,6 @@ static int CmdNoralsyClone(const char *Cmd) {
uint16_t year = 0;
uint32_t id = 0;
uint32_t blocks[4] = {T55x7_MODULATION_MANCHESTER | T55x7_BITRATE_RF_32 | T55x7_ST_TERMINATOR | 3 << T55x7_MAXBLOCK_SHIFT, 0, 0};
uint8_t *bits = calloc(96, sizeof(uint8_t));
char cmdp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) == 0 || cmdp == 'h') return usage_lf_noralsy_clone();
@ -154,8 +153,10 @@ static int CmdNoralsyClone(const char *Cmd) {
if (tolower(param_getchar(Cmd, 2) == 'q'))
blocks[0] = T5555_MODULATION_MANCHESTER | T5555_SET_BITRATE(32) | T5555_ST_TERMINATOR | 3 << T5555_MAXBLOCK_SHIFT;
uint8_t *bits = calloc(96, sizeof(uint8_t));
if (getnoralsyBits(id, year, bits) != PM3_SUCCESS) {
PrintAndLogEx(ERR, "Error with tag bitstream generation.");
free(bits);
return PM3_ESOFT;
}

View file

@ -217,16 +217,14 @@ static int CmdPyramidClone(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) == 0 || cmdp == 'h') return usage_lf_pyramid_clone();
uint32_t facilitycode = 0, cardnumber = 0, fc = 0, cn = 0;
if (sscanf(Cmd, "%u %u", &fc, &cn) != 2) return usage_lf_pyramid_clone();
uint32_t blocks[5];
uint8_t *bs = calloc(128, sizeof(uint8_t));
if (bs == NULL) {
return PM3_EMALLOC;
}
if (sscanf(Cmd, "%u %u", &fc, &cn) != 2) return usage_lf_pyramid_clone();
facilitycode = (fc & 0x000000FF);
cardnumber = (cn & 0x0000FFFF);

View file

@ -2446,6 +2446,7 @@ static int CmdResetRead(const char *Cmd) {
if (!GetFromDevice(BIG_BUF, got, sizeof(got), 0, NULL, 0, NULL, 2500, false)) {
PrintAndLogEx(WARNING, "command execution time out");
free(got);
return PM3_ETIMEOUT;
}
setGraphBuf(got, sizeof(got));

View file

@ -60,6 +60,7 @@ static int CmdScriptRun(const char *Cmd) {
int error;
if (luascriptfile_idx == MAX_NESTED_LUASCRIPT) {
PrintAndLogEx(ERR, "Too many nested scripts, skipping %s\n", script_path);
free(script_path);
return PM3_EMALLOC;
}
PrintAndLogEx(SUCCESS, "Executing Lua script: %s, args '%s'\n", script_path, arguments);

View file

@ -302,7 +302,8 @@ static void PacketResponseReceived(PacketResponseNG *packet) {
break;
}
case CMD_DEBUG_PRINT_INTEGERS: {
PrintAndLogEx(NORMAL, "#db# %" PRIx64 ", %" PRIx64 ", %" PRIx64 "", packet->oldarg[0], packet->oldarg[1], packet->oldarg[2]);
if (! packet->ng)
PrintAndLogEx(NORMAL, "#db# %" PRIx64 ", %" PRIx64 ", %" PRIx64 "", packet->oldarg[0], packet->oldarg[1], packet->oldarg[2]);
break;
}
// iceman: hw status - down the path on device, runs printusbspeed which starts sending a lot of

View file

@ -752,6 +752,7 @@ static void ProcessACResponseFormat1(struct tlvdb *tlvRoot, uint8_t *buf, size_t
if (decodeTLV)
TLVPrintFromTLV(tlvElm);
}
tlvdb_free(tlvElm);
}
} else {
if (decodeTLV)

View file

@ -410,7 +410,6 @@ int loadFile(const char *preferredName, const char *suffix, void *data, size_t m
}
size_t bytes_read = fread(dump, 1, fsize, f);
fclose(f);
if (bytes_read != fsize) {
PrintAndLogEx(FAILED, "error, bytes read mismatch file size");
@ -432,6 +431,7 @@ int loadFile(const char *preferredName, const char *suffix, void *data, size_t m
*datalen = bytes_read;
out:
fclose(f);
free(fileName);
return retval;
}
@ -444,8 +444,6 @@ int loadFile_safe(const char *preferredName, const char *suffix, void **pdata, s
return PM3_EFILE;
}
int retval = PM3_SUCCESS;
FILE *f = fopen(path, "rb");
if (!f) {
PrintAndLogEx(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", path);
@ -478,13 +476,14 @@ int loadFile_safe(const char *preferredName, const char *suffix, void **pdata, s
if (bytes_read != fsize) {
PrintAndLogEx(FAILED, "error, bytes read mismatch file size");
free(*pdata);
return PM3_EFILE;
}
*datalen = bytes_read;
PrintAndLogEx(SUCCESS, "loaded %zu bytes from binary file " _YELLOW_("%s"), bytes_read, preferredName);
return retval;
return PM3_SUCCESS;
}
int loadFileEML(const char *preferredName, void *data, size_t *datalen) {
@ -782,7 +781,9 @@ int loadFileDICTIONARY_safe(const char *preferredName, void **pdata, uint8_t key
*pdata = realloc(*pdata, mem_size);
if (*pdata == NULL) {
return PM3_EFILE;
retval = PM3_EFILE;
fclose(f);
goto out;
} else {
memset(*pdata + (mem_size - block_size), 0, block_size);
}
@ -1058,8 +1059,12 @@ int searchFile(char **foundpath, const char *pm3dir, const char *searchname, con
char *filename = filenamemcopy(searchname, suffix);
if (filename == NULL || strlen(filename) == 0)
if (filename == NULL)
return PM3_EMALLOC;
if (strlen(filename) == 0) {
free(filename);
return PM3_EFILE;
}
int res = searchFinalFile(foundpath, pm3dir, filename, silent);
if (res != PM3_SUCCESS) {
if ((res == PM3_EFILE) && (!silent))

View file

@ -210,14 +210,13 @@ uint8_t GetPskCarrier(const char *str, bool printAns) {
}
uint16_t fc = countFC(bits, size, false);
free(bits);
carrier = fc & 0xFF;
if (carrier != 2 && carrier != 4 && carrier != 8) return 0;
if ((fc >> 8) == 10 && carrier == 8) return 0;
// Only print this message if we're not looping something
if (printAns)
PrintAndLogEx(SUCCESS, "Auto-detected PSK carrier rate: %d", carrier);
free(bits);
return carrier;
}

View file

@ -577,6 +577,7 @@ int mfEmlSetMem_xt(uint8_t *data, int blockNum, int blocksCount, int blockBtWidt
clearCommandBuffer();
SendCommandNG(CMD_HF_MIFARE_EML_MEMSET, (uint8_t *)payload, sizeof(payload) + size);
free(payload);
return PM3_SUCCESS;
}

View file

@ -386,7 +386,7 @@ static int flash_pm3(char *serial_port_name, uint8_t num_files, char *filenames[
int ret = PM3_EUNDEF;
flash_file_t files[FLASH_MAX_FILES];
memset(files, 0, sizeof(files));
char *filepaths[FLASH_MAX_FILES];
char *filepaths[FLASH_MAX_FILES] = {0};
if (serial_port_name == NULL) {
PrintAndLogEx(ERR, "You must specify a port.\n");

View file

@ -1074,6 +1074,7 @@ static int l_searchfile(lua_State *L) {
}
lua_pushstring(L, path);
free(path);
return 1;
}