summaryrefslogtreecommitdiff
path: root/src/arch
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-02-05 22:03:38 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-02-05 22:03:38 (GMT)
commit17f591f2230ac66394467d5e5eefe71cb259637d (patch)
tree1664e994b2904e5e9009027fc57749a11667365b /src/arch
parentff187d24b7441e88e1f0361d59b0f6f55851791f (diff)
Fixed a huge number of memory leaks.
Diffstat (limited to 'src/arch')
-rw-r--r--src/arch/context.c11
-rw-r--r--src/arch/instruction.c21
-rw-r--r--src/arch/link.c1
-rw-r--r--src/arch/processor.c16
-rw-r--r--src/arch/target.c11
5 files changed, 37 insertions, 23 deletions
diff --git a/src/arch/context.c b/src/arch/context.c
index cedec33..3b78161 100644
--- a/src/arch/context.c
+++ b/src/arch/context.c
@@ -144,7 +144,7 @@ static void g_proc_context_dispose(GProcContext *ctx)
size_t i; /* Boucle de parcours */
for (i = 0; i < ctx->items_count; i++)
- g_object_unref(G_OBJECT(ctx->items[i]));
+ g_clear_object(&ctx->items[i]);
g_mutex_clear(&ctx->items_mutex);
@@ -167,6 +167,15 @@ static void g_proc_context_dispose(GProcContext *ctx)
static void g_proc_context_finalize(GProcContext *ctx)
{
+ DisassPriorityLevel i; /* Boucle de parcours */
+
+ for (i = 0; i < DPL_COUNT; i++)
+ if (ctx->drop_points[i] != NULL)
+ free(ctx->drop_points[i]);
+
+ if (ctx->extra_symbols != NULL)
+ free(ctx->extra_symbols);
+
if (ctx->items != NULL)
free(ctx->items);
diff --git a/src/arch/instruction.c b/src/arch/instruction.c
index 1d1ccaf..8e9d3d3 100644
--- a/src/arch/instruction.c
+++ b/src/arch/instruction.c
@@ -607,15 +607,11 @@ bool _g_arch_instruction_replace_operand(GArchInstruction *instr, GArchOperand *
count = _g_arch_instruction_count_operands(instr);
- for (i = 0; i < count; i++)
+ for (i = 0; i < count && !result; i++)
{
op = _g_arch_instruction_get_operand(instr, i);
- if (op == old)
- {
- result = true;
- break;
- }
+ result = (op == old);
g_object_unref(G_OBJECT(op));
@@ -623,7 +619,7 @@ bool _g_arch_instruction_replace_operand(GArchInstruction *instr, GArchOperand *
if (result)
{
- rpl_item_in_flat_array(instr->operands, i, &new, sizeof(GArchOperand *));
+ rpl_item_in_flat_array(instr->operands, i - 1, &new, sizeof(GArchOperand *));
g_object_unref(G_OBJECT(old));
@@ -654,24 +650,23 @@ bool _g_arch_instruction_detach_operand(GArchInstruction *instr, GArchOperand *t
size_t i; /* Boucle de parcours */
GArchOperand *op; /* Opérande à manipuler */
+ result = false;
+
count = _g_arch_instruction_count_operands(instr);
- for (i = 0; i < count; i++)
+ for (i = 0; i < count && !result; i++)
{
op = _g_arch_instruction_get_operand(instr, i);
- if (op == target)
- break;
+ result = (op == target);
g_object_unref(G_OBJECT(op));
}
- result = (i < count);
-
if (result)
{
- rem_item_from_flat_array(&instr->operands, i, sizeof(GArchOperand *));
+ rem_item_from_flat_array(&instr->operands, i - 1, sizeof(GArchOperand *));
g_object_unref(G_OBJECT(target));
diff --git a/src/arch/link.c b/src/arch/link.c
index f09621e..7eaa1d9 100644
--- a/src/arch/link.c
+++ b/src/arch/link.c
@@ -138,7 +138,6 @@ void handle_branch_as_link(GArchInstruction *instr, GArchProcessor *proc, GProcC
}
- range = g_arch_instruction_get_range(instr);
compute_mrange_end_addr(range, &next);
target = g_arch_processor_find_instr_by_address(proc, &next);
diff --git a/src/arch/processor.c b/src/arch/processor.c
index 05e3206..dccd12e 100644
--- a/src/arch/processor.c
+++ b/src/arch/processor.c
@@ -190,8 +190,18 @@ static void g_arch_processor_dispose(GArchProcessor *proc)
size_t i; /* Boucle de parcours */
for (i = 0; i < proc->instr_count; i++)
+ {
+ /**
+ * Pour éviter un cycle de maintien des références, on détruit tous
+ * les liens depuis l'extérieur !
+ */
+ if (proc->instructions[i] != NULL)
+ g_arch_instruction_delete_all_links(proc->instructions[i]);
+
g_clear_object(&proc->instructions[i]);
+ }
+
g_mutex_clear(&proc->mutex);
g_mutex_clear(&proc->error_mutex);
@@ -230,6 +240,9 @@ static void g_arch_processor_finalize(GArchProcessor *proc)
}
+ if (proc->coverages != NULL)
+ free(proc->coverages);
+
G_OBJECT_CLASS(g_arch_processor_parent_class)->finalize(G_OBJECT(proc));
}
@@ -974,8 +987,7 @@ static void g_arch_processor_add_new_coverage(GArchProcessor *proc, GArchInstruc
{
proc->cov_allocated += COV_ALLOC_BLOCK;
- proc->coverages = (instr_coverage *)realloc(proc->coverages,
- proc->cov_allocated * sizeof(instr_coverage));
+ proc->coverages = realloc(proc->coverages, proc->cov_allocated * sizeof(instr_coverage));
}
diff --git a/src/arch/target.c b/src/arch/target.c
index 64b12dd..d3bd89a 100644
--- a/src/arch/target.c
+++ b/src/arch/target.c
@@ -51,6 +51,7 @@ struct _GTargetOperand
vmpa2t addr; /* Adresse de l'élément visé */
bool strict; /* Résolution stricte */
+ /* Référence circulaire */
GBinSymbol *symbol; /* Eventuel symbole associé */
phys_t diff; /* Position dans le symbole */
@@ -206,9 +207,6 @@ static void g_target_operand_targetable_interface_init(GTargetableOperandInterfa
static void g_target_operand_dispose(GTargetOperand *operand)
{
- if (operand->symbol != NULL)
- g_object_unref(G_OBJECT(operand->symbol));
-
G_OBJECT_CLASS(g_target_operand_parent_class)->dispose(G_OBJECT(operand));
}
@@ -505,9 +503,6 @@ bool g_target_operand_resolve(GTargetOperand *operand, GBinFormat *format, bool
const mrange_t *range; /* Couverture du symbole */
#endif
- if (operand->symbol != NULL)
- g_object_unref(G_OBJECT(operand->symbol));
-
operand->strict = strict;
result = g_binary_format_resolve_symbol(format, &operand->addr, strict, &operand->symbol, &operand->diff);
@@ -553,6 +548,10 @@ bool g_target_operand_resolve(GTargetOperand *operand, GBinFormat *format, bool
}
+ /* Référence circulaire */
+ if (operand->symbol != NULL)
+ g_object_unref(operand->symbol);
+
return result;
}