mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2024-12-23 00:25:27 +00:00
uc: Move hook freeing code to its own function
Avoids unrelated variables being in a larger scope than they need to be
This commit is contained in:
parent
7de8b9c67f
commit
a8085d5a38
43
uc.c
43
uc.c
|
@ -296,13 +296,31 @@ static void ramlist_free_dirty_memory(struct uc_struct *uc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void free_hooks(uc_engine *uc)
|
||||||
|
{
|
||||||
|
struct list_item *cur;
|
||||||
|
struct hook *hook;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
// free hooks and hook lists
|
||||||
|
for (i = 0; i < UC_HOOK_MAX; i++) {
|
||||||
|
cur = uc->hook[i].head;
|
||||||
|
// hook can be in more than one list
|
||||||
|
// so we refcount to know when to free
|
||||||
|
while (cur) {
|
||||||
|
hook = (struct hook *)cur->data;
|
||||||
|
if (--hook->refs == 0) {
|
||||||
|
free(hook);
|
||||||
|
}
|
||||||
|
cur = cur->next;
|
||||||
|
}
|
||||||
|
list_clear(&uc->hook[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
UNICORN_EXPORT
|
UNICORN_EXPORT
|
||||||
uc_err uc_close(uc_engine *uc)
|
uc_err uc_close(uc_engine *uc)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
struct list_item *cur;
|
|
||||||
struct hook *hook;
|
|
||||||
|
|
||||||
// Cleanup internally.
|
// Cleanup internally.
|
||||||
if (uc->release)
|
if (uc->release)
|
||||||
uc->release(uc->tcg_ctx);
|
uc->release(uc->tcg_ctx);
|
||||||
|
@ -344,22 +362,7 @@ uc_err uc_close(uc_engine *uc)
|
||||||
g_hash_table_destroy(uc->type_table);
|
g_hash_table_destroy(uc->type_table);
|
||||||
|
|
||||||
ramlist_free_dirty_memory(uc);
|
ramlist_free_dirty_memory(uc);
|
||||||
|
free_hooks(uc);
|
||||||
// free hooks and hook lists
|
|
||||||
for (i = 0; i < UC_HOOK_MAX; i++) {
|
|
||||||
cur = uc->hook[i].head;
|
|
||||||
// hook can be in more than one list
|
|
||||||
// so we refcount to know when to free
|
|
||||||
while (cur) {
|
|
||||||
hook = (struct hook *)cur->data;
|
|
||||||
if (--hook->refs == 0) {
|
|
||||||
free(hook);
|
|
||||||
}
|
|
||||||
cur = cur->next;
|
|
||||||
}
|
|
||||||
list_clear(&uc->hook[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(uc->mapped_blocks);
|
free(uc->mapped_blocks);
|
||||||
|
|
||||||
// finally, free uc itself.
|
// finally, free uc itself.
|
||||||
|
|
Loading…
Reference in a new issue