Fix use-after-free

This commit is contained in:
Simon Kelley
2013-02-05 14:56:02 +00:00
parent 4ead40cf67
commit 25c4198f7c

View File

@@ -91,16 +91,19 @@ static dbus_bool_t add_watch(DBusWatch *watch, void *data)
static void remove_watch(DBusWatch *watch, void *data) static void remove_watch(DBusWatch *watch, void *data)
{ {
struct watch **up, *w; struct watch **up, *w, *tmp;
for (up = &(daemon->watches), w = daemon->watches; w; w = w->next) for (up = &(daemon->watches), w = daemon->watches; w; w = tmp)
{
tmp = w->next;
if (w->watch == watch) if (w->watch == watch)
{ {
*up = w->next; *up = tmp;
free(w); free(w);
} }
else else
up = &(w->next); up = &(w->next);
}
w = data; /* no warning */ w = data; /* no warning */
} }