From 0987d552315b5781157846c23eee0ddaab4702d7 Mon Sep 17 00:00:00 2001 From: Tiago Cunha Date: Sun, 18 Mar 2012 01:59:34 +0000 Subject: [PATCH] Sync OpenBSD patchset 1057: Check event_initialized before event_del if event may not have been set up; libevent2 complains about this. Reported by Moriyoshi Koizumi. --- names.c | 3 ++- server-client.c | 9 ++++++--- server-fn.c | 6 ++++-- status.c | 3 ++- tty-keys.c | 6 ++++-- tty.c | 3 ++- window.c | 3 ++- 7 files changed, 22 insertions(+), 11 deletions(-) diff --git a/names.c b/names.c index dade154f..1dbc26dd 100644 --- a/names.c +++ b/names.c @@ -36,7 +36,8 @@ queue_window_name(struct window *w) tv.tv_sec = 0; tv.tv_usec = NAME_INTERVAL * 1000L; - evtimer_del(&w->name_timer); + if (event_initialized(&w->name_timer)) + evtimer_del(&w->name_timer); evtimer_set(&w->name_timer, window_name_callback, w); evtimer_add(&w->name_timer, &tv); } diff --git a/server-client.c b/server-client.c index c53d0d97..a88230d4 100644 --- a/server-client.c +++ b/server-client.c @@ -152,11 +152,13 @@ server_client_lost(struct client *c) evtimer_del(&c->repeat_timer); - evtimer_del(&c->identify_timer); + if (event_initialized(&c->identify_timer)) + evtimer_del(&c->identify_timer); if (c->message_string != NULL) xfree(c->message_string); - evtimer_del(&c->message_timer); + if (event_initialized (&c->message_timer)) + evtimer_del(&c->message_timer); for (i = 0; i < ARRAY_LENGTH(&c->message_log); i++) { msg = &ARRAY_ITEM(&c->message_log, i); xfree(msg->msg); @@ -175,7 +177,8 @@ server_client_lost(struct client *c) close(c->ibuf.fd); imsg_clear(&c->ibuf); - event_del(&c->event); + if (event_initialized(&c->event)) + event_del(&c->event); for (i = 0; i < ARRAY_LENGTH(&dead_clients); i++) { if (ARRAY_ITEM(&dead_clients, i) == NULL) { diff --git a/server-fn.c b/server-fn.c index 1de34fd1..121077ec 100644 --- a/server-fn.c +++ b/server-fn.c @@ -453,7 +453,8 @@ server_set_identify(struct client *c) tv.tv_sec = delay / 1000; tv.tv_usec = (delay % 1000) * 1000L; - evtimer_del(&c->identify_timer); + if (event_initialized (&c->identify_timer)) + evtimer_del(&c->identify_timer); evtimer_set(&c->identify_timer, server_callback_identify, c); evtimer_add(&c->identify_timer, &tv); @@ -491,7 +492,8 @@ server_update_event(struct client *c) events |= EV_READ; if (c->ibuf.w.queued > 0) events |= EV_WRITE; - event_del(&c->event); + if (event_initialized(&c->event)) + event_del(&c->event); event_set(&c->event, c->ibuf.fd, events, server_client_callback, c); event_add(&c->event, NULL); } diff --git a/status.c b/status.c index 7f10ba0b..8a5f20b0 100644 --- a/status.c +++ b/status.c @@ -776,7 +776,8 @@ status_message_set(struct client *c, const char *fmt, ...) tv.tv_sec = delay / 1000; tv.tv_usec = (delay % 1000) * 1000L; - evtimer_del(&c->message_timer); + if (event_initialized (&c->message_timer)) + evtimer_del(&c->message_timer); evtimer_set(&c->message_timer, status_message_callback, c); evtimer_add(&c->message_timer, &tv); diff --git a/tty-keys.c b/tty-keys.c index fb88d9e0..fcf3a529 100644 --- a/tty-keys.c +++ b/tty-keys.c @@ -549,7 +549,8 @@ start_timer: tv.tv_sec = delay / 1000; tv.tv_usec = (delay % 1000) * 1000L; - evtimer_del(&tty->key_timer); + if (event_initialized(&tty->key_timer)) + evtimer_del(&tty->key_timer); evtimer_set(&tty->key_timer, tty_keys_callback, tty); evtimer_add(&tty->key_timer, &tv); @@ -573,7 +574,8 @@ found_key: goto handle_key; handle_key: - evtimer_del(&tty->key_timer); + if (event_initialized(&tty->key_timer)) + evtimer_del(&tty->key_timer); if (key != KEYC_NONE) tty->key_callback(key, &mouse, tty->key_data); diff --git a/tty.c b/tty.c index 65bfe6c8..3f8b5d0a 100644 --- a/tty.c +++ b/tty.c @@ -279,7 +279,8 @@ tty_close(struct tty *tty) tty->log_fd = -1; } - evtimer_del(&tty->key_timer); + if (event_initialized(&tty->key_timer)) + evtimer_del(&tty->key_timer); tty_stop_tty(tty); if (tty->flags & TTY_OPENED) { diff --git a/window.c b/window.c index aa25f442..3310b91f 100644 --- a/window.c +++ b/window.c @@ -347,7 +347,8 @@ window_destroy(struct window *w) if (w->layout_root != NULL) layout_free(w); - evtimer_del(&w->name_timer); + if (event_initialized(&w->name_timer)) + evtimer_del(&w->name_timer); options_free(&w->options);