This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

bench: close timer handles before deleting loop

Fixes a segmentation fault / use-after-free.
  • Loading branch information...
bnoordhuis committed Nov 13, 2012
1 parent 3243e9a commit b9c8d196379dc28a9ed503a2695581d6698ba466
Showing with 11 additions and 0 deletions.
  1. +11 −0 test/benchmark-million-timers.c
@@ -25,13 +25,19 @@
#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) {
timer_cb_called++;
}
+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);

0 comments on commit b9c8d19

Please sign in to comment.