Skip to content

Commit

Permalink
uv_type: make ~uv_type() destructor protected
Browse files Browse the repository at this point in the history
Make the destructor for `uv_type` `protected`, in order to the fix the
`-Wnon-virtual-dtor` warnings:

```
‘struct uvw::uv_type<uv_async_s>’ has virtual functions and accessible non-virtual destructor [-Werror=non-virtual-dtor]
```

As an example, the code below currently works (casting a pointer to a
subclass of `uvw::uv_type` to `uvw::uv_type`, but it causes a memory
leak, since only the `uvw::uv_type` destructor is called.

Doing this is now forbidden.

```c++
uvw::resource<...>* will_leak;
auto abc = std::unique_ptr<uvw::uv_type>(will_leak);
```

BREAKING CHANGE: This change may break the uvw ABI.
                 It also breaks the API.
  • Loading branch information
aloisklink committed Aug 23, 2023
1 parent 36b586f commit 820e9be
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/uvw/uv_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ struct uv_type {
return &resource;
}

protected:
~uv_type() = default;

private:
std::shared_ptr<loop> owner;
U resource;
Expand Down

0 comments on commit 820e9be

Please sign in to comment.