From a10844d4bfd1e31bd062af9aae65add0e70cc136 Mon Sep 17 00:00:00 2001 From: Stefano Fiorentino Date: Sun, 19 Jul 2020 12:08:36 +0200 Subject: [PATCH] basehandle::type() in uv_walk which is in a timer callback causes double free (#213) Close #212 --- src/uvw/loop.h | 1 + test/uvw/timer.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/uvw/loop.h b/src/uvw/loop.h index 9832f0fd..98247daf 100644 --- a/src/uvw/loop.h +++ b/src/uvw/loop.h @@ -46,6 +46,7 @@ enum class UVRunMode: std::underlying_type_t { * This can help to end all the pending requests by closing the handles. */ struct BaseHandle { + virtual ~BaseHandle() = default; /** * @brief Gets the category of the handle. * diff --git a/test/uvw/timer.cpp b/test/uvw/timer.cpp index f07add7a..e484af09 100644 --- a/test/uvw/timer.cpp +++ b/test/uvw/timer.cpp @@ -122,3 +122,17 @@ TEST(Timer, Fake) { loop->run(); } + +TEST(Timer, BaseHandleWalk) { + auto loop = uvw::Loop::getDefault(); + auto timer = loop->resource(); + timer->on([](const auto &event, uvw::TimerHandle &handle) { + auto &loop = handle.loop(); + loop.walk([](uvw::BaseHandle& h){ + h.type(); + }); + handle.close(); + }); + timer->start(uvw::TimerHandle::Time{1000}, uvw::TimerHandle::Time{1000}); + loop->run(); +}