Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

bench: close timer handles before deleting loop

Fixes a segmentation fault / use-after-free.
  • Loading branch information...
commit b9c8d196379dc28a9ed503a2695581d6698ba466 1 parent 3243e9a
@bnoordhuis bnoordhuis authored
Showing with 11 additions and 0 deletions.
  1. +11 −0 test/benchmark-million-timers.c
View
11 test/benchmark-million-timers.c
@@ -25,6 +25,7 @@
#define NUM_TIMERS (1000 * 1000)
static int timer_cb_called;
+static int close_cb_called;
static void timer_cb(uv_timer_t* handle, int status) {
@@ -32,6 +33,11 @@ static void timer_cb(uv_timer_t* handle, int status) {
}
+static void close_cb(uv_handle_t* handle) {
+ close_cb_called++;
+}
+
+
BENCHMARK_IMPL(million_timers) {
uv_timer_t* timers;
uv_loop_t* loop;
@@ -56,7 +62,12 @@ BENCHMARK_IMPL(million_timers) {
ASSERT(0 == uv_run(loop));
after = uv_hrtime();
+ for (i = 0; i < NUM_TIMERS; i++)
+ uv_close((uv_handle_t*) (timers + i), close_cb);
+
+ ASSERT(0 == uv_run(loop));
ASSERT(timer_cb_called == NUM_TIMERS);
+ ASSERT(close_cb_called == NUM_TIMERS);
free(timers);
LOGF("%.2f seconds\n", (after - before) / 1e9);
Please sign in to comment.
Something went wrong with that request. Please try again.