fix memleak

This commit is contained in:
iceman1001 2020-05-27 20:33:25 +02:00
commit 2ae85dea4e

View file

@ -147,12 +147,6 @@ static int testkey(uint64_t *out, uint64_t uid, uint64_t pkey, uint64_t nR, uint
return 0; return 0;
} }
// some notes on how I think this attack should work. // some notes on how I think this attack should work.
// due to the way fc works, in a number of cases, it doesn't matter what // due to the way fc works, in a number of cases, it doesn't matter what
// the most significant bits are doing for it to produce the same result. // the most significant bits are doing for it to produce the same result.
@ -177,7 +171,6 @@ static int testkey(uint64_t *out, uint64_t uid, uint64_t pkey, uint64_t nR, uint
// limit our guesses to a smaller set than a full brute force and // limit our guesses to a smaller set than a full brute force and
// effectively work out candidates for the lower 34 bits of the key. // effectively work out candidates for the lower 34 bits of the key.
static void *crack(void *d) { static void *crack(void *d) {
struct threaddata *data = (struct threaddata *)d; struct threaddata *data = (struct threaddata *)d;
uint64_t uid; uint64_t uid;
@ -187,21 +180,14 @@ static void *crack(void *d) {
Hitag_State hstate; Hitag_State hstate;
int i, j; int i, j;
uint64_t klower; uint64_t klower, kmiddle, klowery;
uint64_t kmiddle; uint64_t y, b, z, bit;
uint64_t y;
uint64_t ytmp; uint64_t ytmp;
uint64_t klowery;
unsigned int count; unsigned int count;
uint64_t bit; uint64_t foundkey, revkey;
uint64_t b;
uint64_t z;
uint64_t foundkey;
uint64_t revkey;
int ret; int ret;
unsigned int found; unsigned int found;
unsigned int badguess; unsigned int badguess;
struct Tklower *Tk = NULL; struct Tklower *Tk = NULL;
if (!data) { if (!data) {
@ -216,7 +202,7 @@ static void *crack(void *d) {
// create space for tables // create space for tables
Tk = (struct Tklower *)malloc(sizeof(struct Tklower) * 0x40000); Tk = (struct Tklower *)malloc(sizeof(struct Tklower) * 0x40000);
if (!Tk) { if (!Tk) {
printf("cannot malloc Tk\n"); printf("Failed to allocate memory (Tk)\n");
exit(1); exit(1);
} }
@ -301,6 +287,7 @@ static void *crack(void *d) {
} }
} }
free(Tk);
return NULL; return NULL;
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
@ -383,7 +370,6 @@ int main(int argc, char *argv[]) {
// close file // close file
fclose(fp); fclose(fp);
fp = NULL;
printf("Loaded %u NrAr pairs\n", numnrar); printf("Loaded %u NrAr pairs\n", numnrar);