more efficient hook removal

This commit is contained in:
Ryan Hileman 2016-03-25 20:25:18 -07:00
parent 8c58da4416
commit d5e85cf3f9

12
uc.c
View file

@ -1029,16 +1029,20 @@ uc_err uc_hook_add(uc_engine *uc, uc_hook *hh, int type, void *callback,
UNICORN_EXPORT UNICORN_EXPORT
uc_err uc_hook_del(uc_engine *uc, uc_hook hh) uc_err uc_hook_del(uc_engine *uc, uc_hook hh)
{ {
int i; int i = 0;
struct hook *hook; struct hook *hook = (struct hook *)hh;
for (i = 0; i < UC_HOOK_MAX; i++) { int type = hook->type;
while ((type >> i) > 0 && i < UC_HOOK_MAX) {
if ((type >> i) & 1) {
if (list_remove(&uc->hook[i], (void *)hh)) { if (list_remove(&uc->hook[i], (void *)hh)) {
hook = (struct hook *)hh;
if (--hook->refs == 0) { if (--hook->refs == 0) {
free(hook); free(hook);
} }
} }
} }
i++;
}
return UC_ERR_OK; return UC_ERR_OK;
} }