shl: hook: fix invalid memory access for non-oneshot entries
authorDavid Herrmann <dh.herrmann@googlemail.com>
Sun, 13 Jan 2013 18:30:35 +0000 (19:30 +0100)
committerDavid Herrmann <dh.herrmann@googlemail.com>
Sun, 13 Jan 2013 18:30:35 +0000 (19:30 +0100)
If an entry is not a oneshot entry, then it might get deleted during the
callback procedure and hence, we _must_ not access it afterwards.
Therefore, remember the oneshot setting so we access it only if it really
is a oneshot entry.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
src/shl_hook.h

index be64b74..66603a0 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * shl - Hook Handling
  *
- * Copyright (c) 2011-2012 David Herrmann <dh.herrmann@googlemail.com>
+ * Copyright (c) 2011-2013 David Herrmann <dh.herrmann@googlemail.com>
  * Copyright (c) 2011 University of Tuebingen
  *
  * Permission is hereby granted, free of charge, to any person obtaining
@@ -205,6 +205,7 @@ static inline void shl_hook_call(struct shl_hook *hook, void *parent,
                                 void *arg)
 {
        struct shl_hook_entry *entry;
+       bool oneshot;
 
        if (!hook || hook->cur_entry)
                return;
@@ -214,13 +215,14 @@ static inline void shl_hook_call(struct shl_hook *hook, void *parent,
                entry = shl_dlist_entry(hook->cur_entry,
                                        struct shl_hook_entry, list);
                hook->cur_entry = entry->list.next;
+               oneshot = entry->oneshot;
 
-               if (entry->oneshot)
+               if (oneshot)
                        shl_dlist_unlink(&entry->list);
 
                entry->cb(parent, arg, entry->data);
 
-               if (entry->oneshot) {
+               if (oneshot) {
                        free(entry);
                        --hook->num;
                }