Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,18 @@ void
hashtable_delete (hashtable_t *ht)
{
for (size_t i = 0; i < ht->size; i++)
free (ht->buckets[i]);
{
if (ht->buckets[i])
{
size_t j = 0;
while (ht->buckets[i][j])
{
instr_delete (ht->buckets[i][j]);
j++;
}
}
free (ht->buckets[i]);
}
free (ht);
}

Expand Down Expand Up @@ -191,7 +202,7 @@ hashtable_insert (hashtable_t * ht, instr_t * instr)
size_t k = 0;
while (ht->buckets[index][k] != NULL)
if (ht->buckets[index][k++]->address == instr->address)
return true;
return false; /* No error but we need to delete the redundant one */

instr_t **new_bucket = calloc (k + 2, sizeof (instr_t *));
if (!new_bucket)
Expand Down
10 changes: 8 additions & 2 deletions src/tracker.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,9 @@ main (int argc, char *argv[], char *envp[])
/* Create the instr_t structure */
instr_t *instr = instr_new (ip, insn[0].size, buf);
if (!instr)
err (EXIT_FAILURE, "error:");
err (EXIT_FAILURE, "error: cannot create instruction");

cs_free (insn, count);

if (!hashtable_insert (ht, instr))
instr_delete (instr);
Expand All @@ -338,7 +340,9 @@ main (int argc, char *argv[], char *envp[])
while (ptrace(PTRACE_SINGLESTEP, child, NULL, NULL));
}

fprintf(output,
cs_close (&handle);

fprintf (output,
"\n"
"\tStatistics about this run\n"
"\t=========================\n"
Expand All @@ -351,5 +355,7 @@ main (int argc, char *argv[], char *envp[])

hashtable_delete (ht);



return EXIT_SUCCESS;
}