hook: don't remove from unitialized list

A lot of code calls spa_hook_remove() from error paths where the hook
and therefore the list may not have been initialized.
This leads to null-derefences.
This commit is contained in:
Thomas Weißschuh 2022-08-23 23:47:52 +02:00 committed by Wim Taymans
parent b23b0e6125
commit 2394413ec3
2 changed files with 8 additions and 1 deletions

View File

@ -382,7 +382,8 @@ static inline void spa_hook_list_prepend(struct spa_hook_list *list,
/** Remove a hook */
static inline void spa_hook_remove(struct spa_hook *hook)
{
spa_list_remove(&hook->link);
if (spa_list_is_initialized(&hook->link))
spa_list_remove(&hook->link);
if (hook->removed)
hook->removed(hook);
}

View File

@ -419,6 +419,12 @@ PWTEST(utils_hook)
}
pwtest_int_eq(count, 4);
pwtest_int_eq(hook_free_count, 4);
/* remove a zeroed hook */
struct spa_hook hook;
spa_zero(hook);
spa_hook_remove(&hook);
return PWTEST_PASS;
}