mirror of
https://github.com/libevent/libevent.git
synced 2025-01-31 09:12:55 +08:00
tests: add a test for event_free() from signal callback handler (#1729)
This commit is contained in:
commit
468be957cd
3
event.c
3
event.c
@ -1387,7 +1387,8 @@ event_signal_closure(struct event_base *base, struct event *ev)
|
||||
short ncalls;
|
||||
int should_break;
|
||||
|
||||
/* Allows deletes to work */
|
||||
/* Allows deletes to work, see also event_del_nolock_() that has
|
||||
* special treatment for signals */
|
||||
ncalls = ev->ev_ncalls;
|
||||
if (ncalls != 0)
|
||||
ev->ev_pncalls = &ncalls;
|
||||
|
@ -1086,6 +1086,37 @@ test_simplesignal(void)
|
||||
test_simplesignal_impl(1);
|
||||
}
|
||||
|
||||
/* signal_free_in_callback */
|
||||
static void
|
||||
signal_cb_free_event(evutil_socket_t fd, short event, void *arg)
|
||||
{
|
||||
struct event *ev = arg;
|
||||
event_free(ev);
|
||||
++test_ok;
|
||||
}
|
||||
static void
|
||||
test_signal_free_in_callback(void *ptr)
|
||||
{
|
||||
struct basic_test_data *data = ptr;
|
||||
struct event_base *base = data->base;
|
||||
struct event *ev;
|
||||
|
||||
ev = evsignal_new(base, SIGUSR1, signal_cb_free_event, event_self_cbarg());
|
||||
evsignal_add(ev, NULL);
|
||||
|
||||
kill(getpid(), SIGUSR1);
|
||||
kill(getpid(), SIGUSR1);
|
||||
test_ok = 0;
|
||||
|
||||
event_base_loop(base, 0);
|
||||
tt_int_op(test_ok, ==, 1);
|
||||
test_ok = 0;
|
||||
return;
|
||||
|
||||
end:
|
||||
;
|
||||
}
|
||||
|
||||
static void
|
||||
test_multiplesignal(void)
|
||||
{
|
||||
@ -3666,6 +3697,7 @@ struct testcase_t signal_testcases[] = {
|
||||
LEGACY(signal_restore, TT_ISOLATED),
|
||||
LEGACY(signal_assert, TT_ISOLATED),
|
||||
LEGACY(signal_while_processing, TT_ISOLATED),
|
||||
BASIC(signal_free_in_callback, TT_FORK|TT_NEED_BASE|RETRY_ON_DARWIN),
|
||||
#endif
|
||||
END_OF_TESTCASES
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user