shl: hook: allow callbacks to destroy the hook
If we currently dispatch a callback and they unregister themself and then destroy the hook, we currently do not free the hook as we would free memory that is used in the callstack. However, it is a valid use-case for hook-callbacks to destroy the hook. Therefore, we set a "dead" flag and destroy the hook after all callbacks are done. This fixes some memory-leaks inside the shared-signal callbacks of eloop. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
parent
715287427d
commit
46898b1090
@ -58,6 +58,7 @@ struct shl_hook {
|
||||
unsigned int num;
|
||||
struct shl_dlist entries;
|
||||
struct shl_dlist *cur_entry;
|
||||
bool dead;
|
||||
};
|
||||
|
||||
static inline int shl_hook_new(struct shl_hook **out)
|
||||
@ -81,9 +82,14 @@ static inline void shl_hook_free(struct shl_hook *hook)
|
||||
{
|
||||
struct shl_hook_entry *entry;
|
||||
|
||||
if (!hook || hook->cur_entry)
|
||||
if (!hook)
|
||||
return;
|
||||
|
||||
if (hook->cur_entry) {
|
||||
hook->dead = true;
|
||||
return;
|
||||
}
|
||||
|
||||
while (!shl_dlist_empty(&hook->entries)) {
|
||||
entry = shl_dlist_entry(hook->entries.prev,
|
||||
struct shl_hook_entry,
|
||||
@ -164,6 +170,8 @@ static inline void shl_hook_call(struct shl_hook *hook, void *parent,
|
||||
}
|
||||
|
||||
hook->cur_entry = NULL;
|
||||
if (hook->dead)
|
||||
shl_hook_free(hook);
|
||||
}
|
||||
|
||||
#endif /* SHL_HOOK_H */
|
||||
|
Loading…
x
Reference in New Issue
Block a user